jwilson122 Posted October 10, 2010 Share Posted October 10, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/215529-mysql_query/ Share on other sites More sharing options...
Alex Posted October 10, 2010 Share Posted October 10, 2010 You can use multiple AND clauses like that. That's obviously not the query causing the error (have you changed it?) because there isn't even a LIMIT in that query. Quote Link to comment https://forums.phpfreaks.com/topic/215529-mysql_query/#findComment-1120732 Share on other sites More sharing options...
jwilson122 Posted October 10, 2010 Author Share Posted October 10, 2010 You can use multiple AND clauses like that. That's obviously not the query causing the error (have you changed it?) because there isn't even a LIMIT in that query. Well, how come I get the error? Quote Link to comment https://forums.phpfreaks.com/topic/215529-mysql_query/#findComment-1120733 Share on other sites More sharing options...
PFMaBiSmAd Posted October 10, 2010 Share Posted October 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215529-mysql_query/#findComment-1120734 Share on other sites More sharing options...
jwilson122 Posted October 10, 2010 Author Share Posted October 10, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/215529-mysql_query/#findComment-1120735 Share on other sites More sharing options...
PFMaBiSmAd Posted October 10, 2010 Share Posted October 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215529-mysql_query/#findComment-1120737 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.