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 }
@TuringTest
I'm sorry, I don' know enough about sql or what an ENUM value is.
oh ok nevermind...
thanks anyways
good luck! I would like to learn this as well
@wio
plz help
Are you making an SQL query?
yes
I need a permissions system, so I need to check the value of a certain enum using PHP
So you want the query to filter out data without permission? Or do you want it to come back with true?
I need to check if a certain value exists for the column.. for example if the permissions column contains "yes"..
Normally you'd add ``` WHERE column = 'yes' ``` But not all SQL define ENUM the same
hmm I'll try that..
I would need to know more to give better answer
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
Okay, what do you know about the ENUM?
thats line 28
Okay, where is the SQL for defining the ENUM?
the permissions parameter doesn't seem to work for some reason
The enum parameter is "admin"
Is there a reason you can't tell me about the ENUM? Is it that you don't know?
What enum?
Umm, no. I need to know about the database schema...
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"
Okay, here is what you should do then: get rid of the enum constraint, then print out whatever is in the permissions column
Then you will know what it's current value is, and you can check against it.
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
But the permissions column stores the enum values
Yes, well you don't know what the enum value becomes, right? So just print it out.
Then you will know, then you can check against it
How do I do that, if I could print out the value, then I could also check value.. which is what i need
Okay, so do you have a way to execute queries directly on your database? Like phpMyAdmin?
Yes I do have phpMyAdmin.. i'm using it right now
``` 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.
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
Okay, then maybe try `permissions=admin` without quotes
No it doesn't work, all I get is that parameter 2 is expected to be resource, but string given
okay, the problem isn't enum
` "$connection"` Why you put in quotes?
You shouldn't put it quotes
Yeah, but you put it in quotes
oh lemme try it out again..
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
try 'admin' or admin
yes, only 'admin' works, but I can't seem to echo the variable $adminedit afterwards
What happens when you try?
nothing appears..
try `var_dump($adminedit)`. I think that the problem is that it doesn't get defined.
why should i put that in the code
To figure out what happened to `$adminedit`
I'll try
Outputs: "NULL", Can I not store a string on multiple lines?
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
EOD huh?.. lemme try
``` $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; ```
`<<<HTML` begins string `HTML;` ends string
I'll try that
Only outputs syntax error
what is code?
`HTML;` but be at the start of a new line
must be
No doesn't work either
and `<<<HTML` must be at end of line also, don't need `"`
Is there syntax error?
yes
what is error?
Parse error: syntax error, unexpected T_SL in /home/u677311329/public_html/login.php on line 30
Line 30: $adminedit = <<<HTML
What does code look like now?
You have white space before `HTML;` It must be at the beginning of the line.
Doesn't work either
can I see?
can you give me exact error?
Parse error: syntax error, unexpected T_SL in /home/u677311329/public_html/login.php on line 30
T_SL refers to <<
You should not use tabs or spaces before you use `HTML;`
Can you check if the enum is verified correctly, because the string just outputs null without the <<<HTML
I tried without tabs or spaces, still does not work
the `<<<HTML` and `HTML;` work just like `"` and `"`, but allow multiple line.
Therefore, you don't need to keep `"` in them
still NULL
is there parser error?
nope... NULL... I even preset the $adminedit variable to something else before the condition... outputs null still
Can you show me entire thing?
There is no echo....
Yes, I have the echo on the actual html page
can I see it?
<?php echo $adminedit; ?>
What about variable scope?
does it regard that.. It wont even print out the preset global value.
Join our real-time social learning platform and learn together with your friends!