Jump to content

mysql_query


jwilson122

Recommended Posts

OK So I have a quick question... how would I go about making a query like:

mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND key='$key' ");

You see, theres an error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' key='1234' LIMIT 1' at line 1

 

I know this is a simple issue, and I know you cant keep creating AND's inside the query, but how would I do it? I've never attempted to use more than one AND before, so its new to me even though I'm a experienced PHP Developer. Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/215529-mysql_query/
Share on other sites

key, as you might imagine, has significance to a database query language. It is a reserved key word and you either need to enclose it in back-ticks `` every time you use it in a query, or simply rename your column to something else.

 

oh wow. I added the `key` and it works now. ;) Thanks a lot. I guess everyone learns more every day huh? haha, I know quite a bit and have created scripts from ground up before.. just there are little things like this I still haven't delt with yet. But, now I know! Also btw @AlexWD, yeah I typed the query in the original post, Its not the actual query, mine has a LIMIT 1 in it. Should it? Its a login script... any tips for me anyone?

Link to comment
https://forums.phpfreaks.com/topic/215529-mysql_query/#findComment-1120735
Share on other sites

You should always post the actual code/query... that produces the symptom you need help with. It avoids wild-goose-chases and wasted time. You should not be typing code into posts (unless you are making a reply.) Always (and simply) copy paste actual code. Altering one word or one piece of punctuation changes what code does and changes what we see and what direction to look to find the problem.

Link to comment
https://forums.phpfreaks.com/topic/215529-mysql_query/#findComment-1120737
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.