Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (coconutjj):

How do I check if a certain ENUM value in a sql database is a certain string. For example, PHP: if((data) == "myString"){ do this }

OpenStudy (coconutjj):

@TuringTest

OpenStudy (turingtest):

I'm sorry, I don' know enough about sql or what an ENUM value is.

OpenStudy (coconutjj):

oh ok nevermind...

OpenStudy (coconutjj):

thanks anyways

OpenStudy (turingtest):

good luck! I would like to learn this as well

OpenStudy (coconutjj):

@wio

OpenStudy (coconutjj):

plz help

OpenStudy (anonymous):

Are you making an SQL query?

OpenStudy (coconutjj):

yes

OpenStudy (coconutjj):

I need a permissions system, so I need to check the value of a certain enum using PHP

OpenStudy (anonymous):

So you want the query to filter out data without permission? Or do you want it to come back with true?

OpenStudy (coconutjj):

I need to check if a certain value exists for the column.. for example if the permissions column contains "yes"..

OpenStudy (anonymous):

Normally you'd add ``` WHERE column = 'yes' ``` But not all SQL define ENUM the same

OpenStudy (coconutjj):

hmm I'll try that..

OpenStudy (anonymous):

I would need to know more to give better answer

OpenStudy (coconutjj):

I did that, but the following error: Warning: mysql_query() expects parameter 2 to be resource, string given in /home/u677311329/public_html/login.php on line 28

OpenStudy (anonymous):

Okay, what do you know about the ENUM?

OpenStudy (coconutjj):

http://pastebin.com/1N6Wxj2a

OpenStudy (coconutjj):

thats line 28

OpenStudy (anonymous):

Okay, where is the SQL for defining the ENUM?

OpenStudy (coconutjj):

the permissions parameter doesn't seem to work for some reason

OpenStudy (coconutjj):

The enum parameter is "admin"

OpenStudy (anonymous):

Is there a reason you can't tell me about the ENUM? Is it that you don't know?

OpenStudy (coconutjj):

What enum?

OpenStudy (anonymous):

Umm, no. I need to know about the database schema...

OpenStudy (coconutjj):

I have a column named permissions and inside there are two enum values: "admin","user". I want to check if the specified column contains "admin"

OpenStudy (anonymous):

Okay, here is what you should do then: get rid of the enum constraint, then print out whatever is in the permissions column

OpenStudy (anonymous):

Then you will know what it's current value is, and you can check against it.

OpenStudy (anonymous):

The enum is converted to some integer, but I don't know what integers it's going to be. That's what you should know

OpenStudy (coconutjj):

But the permissions column stores the enum values

OpenStudy (anonymous):

Yes, well you don't know what the enum value becomes, right? So just print it out.

OpenStudy (anonymous):

Then you will know, then you can check against it

OpenStudy (coconutjj):

How do I do that, if I could print out the value, then I could also check value.. which is what i need

OpenStudy (anonymous):

Okay, so do you have a way to execute queries directly on your database? Like phpMyAdmin?

OpenStudy (coconutjj):

Yes I do have phpMyAdmin.. i'm using it right now

OpenStudy (anonymous):

``` SELECT permissions FROM company WHERE username = 'bob'; ``` You can change `bob` to the username of an admin and figure out what the enum corresponds too.

OpenStudy (coconutjj):

Yes i see, I run it with the appropriate username.. I can the value is currently set to "admin". Now how do I store that value into a variable and check the value is equal to a certain ENUM

OpenStudy (anonymous):

Okay, then maybe try `permissions=admin` without quotes

OpenStudy (coconutjj):

No it doesn't work, all I get is that parameter 2 is expected to be resource, but string given

OpenStudy (coconutjj):

http://pastebin.com/ZHG5rdPd Here is my code

OpenStudy (anonymous):

okay, the problem isn't enum

OpenStudy (anonymous):

` "$connection"` Why you put in quotes?

OpenStudy (coconutjj):

You shouldn't put it quotes

OpenStudy (anonymous):

Yeah, but you put it in quotes

OpenStudy (coconutjj):

oh lemme try it out again..

OpenStudy (coconutjj):

THANK YOU!.... but do you have any idea why it can't verify it afterwards... because it doesn't seem to print the $adminedit variable after

OpenStudy (anonymous):

try 'admin' or admin

OpenStudy (coconutjj):

yes, only 'admin' works, but I can't seem to echo the variable $adminedit afterwards

OpenStudy (anonymous):

What happens when you try?

OpenStudy (coconutjj):

nothing appears..

OpenStudy (coconutjj):

http://pastebin.com/EQxcRNYz

OpenStudy (anonymous):

try `var_dump($adminedit)`. I think that the problem is that it doesn't get defined.

OpenStudy (coconutjj):

why should i put that in the code

OpenStudy (anonymous):

To figure out what happened to `$adminedit`

OpenStudy (coconutjj):

I'll try

OpenStudy (coconutjj):

Outputs: "NULL", Can I not store a string on multiple lines?

OpenStudy (coconutjj):

EOD huh?.. lemme try

OpenStudy (anonymous):

``` $adminedit = "<form> <textarea name='editor1' id='editor1' rows='10' cols='80'> This is my textarea to be replaced with CKEditor. </textarea> <script> // Replace the <textarea id='editor1'> with a CKEditor // instance, using default configuration. CKEDITOR.replace('editor1'); </script> </form>"; ``` Should be ``` $adminedit = <<HTML <form> <textarea name='editor1' id='editor1' rows='10' cols='80'> This is my textarea to be replaced with CKEditor. </textarea> <script> // Replace the <textarea id='editor1'> with a CKEditor // instance, using default configuration. CKEDITOR.replace('editor1'); </script> </form> HTML; ```

OpenStudy (anonymous):

`<<<HTML` begins string `HTML;` ends string

OpenStudy (coconutjj):

I'll try that

OpenStudy (coconutjj):

Only outputs syntax error

OpenStudy (anonymous):

what is code?

OpenStudy (coconutjj):

http://pastebin.com/4jZx4TqL

OpenStudy (anonymous):

`HTML;` but be at the start of a new line

OpenStudy (anonymous):

must be

OpenStudy (coconutjj):

No doesn't work either

OpenStudy (anonymous):

and `<<<HTML` must be at end of line also, don't need `"`

OpenStudy (anonymous):

Is there syntax error?

OpenStudy (coconutjj):

yes

OpenStudy (anonymous):

what is error?

OpenStudy (coconutjj):

Parse error: syntax error, unexpected T_SL in /home/u677311329/public_html/login.php on line 30

OpenStudy (coconutjj):

Line 30: $adminedit = <<<HTML

OpenStudy (anonymous):

What does code look like now?

OpenStudy (coconutjj):

http://pastebin.com/bysjh4t8

OpenStudy (anonymous):

You have white space before `HTML;` It must be at the beginning of the line.

OpenStudy (coconutjj):

Doesn't work either

OpenStudy (anonymous):

can I see?

OpenStudy (coconutjj):

http://pastebin.com/tJMXsLv2

OpenStudy (anonymous):

can you give me exact error?

OpenStudy (coconutjj):

Parse error: syntax error, unexpected T_SL in /home/u677311329/public_html/login.php on line 30

OpenStudy (coconutjj):

T_SL refers to <<

OpenStudy (anonymous):

You should not use tabs or spaces before you use `HTML;`

OpenStudy (coconutjj):

Can you check if the enum is verified correctly, because the string just outputs null without the <<<HTML

OpenStudy (coconutjj):

I tried without tabs or spaces, still does not work

OpenStudy (anonymous):

the `<<<HTML` and `HTML;` work just like `"` and `"`, but allow multiple line.

OpenStudy (anonymous):

Therefore, you don't need to keep `"` in them

OpenStudy (coconutjj):

still NULL

OpenStudy (anonymous):

is there parser error?

OpenStudy (coconutjj):

nope... NULL... I even preset the $adminedit variable to something else before the condition... outputs null still

OpenStudy (anonymous):

Can you show me entire thing?

OpenStudy (coconutjj):

http://pastebin.com/6Qf5s4cM

OpenStudy (anonymous):

There is no echo....

OpenStudy (coconutjj):

Yes, I have the echo on the actual html page

OpenStudy (anonymous):

can I see it?

OpenStudy (coconutjj):

<?php echo $adminedit; ?>

OpenStudy (anonymous):

What about variable scope?

OpenStudy (coconutjj):

does it regard that.. It wont even print out the preset global value.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!