nzol Posted April 25, 2011 Share Posted April 25, 2011 I want to get data from mysql database with more than two fields matching in the WHERE clause. For example I want something like this: SELECT * FROM users WHERE town='$town' AND age='$age' AND firstname='$firstname'"); Now for some reason, Mysql does not allow more than two specifications in the WHERE clause. If someone could please tell me away to get around this, it would be very appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/234628-more-than-2-specifications-in-where-clause/ Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 What would make you think MySQL doesn't allow that? Quote Link to comment https://forums.phpfreaks.com/topic/234628-more-than-2-specifications-in-where-clause/#findComment-1205756 Share on other sites More sharing options...
nzol Posted April 25, 2011 Author Share Posted April 25, 2011 Because I tried the query and it said; 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 ' ='1' AND alas='Login failed' AND ns='Page'' at line 1 If you know if it does please tell me! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234628-more-than-2-specifications-in-where-clause/#findComment-1205758 Share on other sites More sharing options...
trq Posted April 25, 2011 Share Posted April 25, 2011 Can we see your actual query? Quote Link to comment https://forums.phpfreaks.com/topic/234628-more-than-2-specifications-in-where-clause/#findComment-1205759 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 It does work. There's got to to be something else wrong with the query. Echo the query string and paste it in here so we can get to the bottom of this . . . (From the look of the error, and the way you formed the query string chunk you posted in the OP, I'm going to go out on a limb and guess that you're using a variable for the field name just prior to `alas` that is supposed to equal 1, and the variable is actually empty.) Quote Link to comment https://forums.phpfreaks.com/topic/234628-more-than-2-specifications-in-where-clause/#findComment-1205761 Share on other sites More sharing options...
nzol Posted April 25, 2011 Author Share Posted April 25, 2011 @Pikachu2000: You are absolutely correct! I accidentally put $ before the field name! Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/234628-more-than-2-specifications-in-where-clause/#findComment-1205766 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 No problem. Glad it was something that simple. Quote Link to comment https://forums.phpfreaks.com/topic/234628-more-than-2-specifications-in-where-clause/#findComment-1205768 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.