Bricktop Posted March 10, 2008 Share Posted March 10, 2008 Hi Guys, Is it possible to have two operators in one Query? For example: SELECT * FROM table WHERE username=$username AND password=$password AND answer=$answer I have tried the above and it doesn't work - where am I going wrong please? How do I write the above so it will work? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/95375-mysql-and-operator/ Share on other sites More sharing options...
trq Posted March 10, 2008 Share Posted March 10, 2008 Yes its possible, you mistake however is tat strings need to be surrounded in quotes. SELECT * FROM table WHERE username='$username' AND password='$password' AND answer='$answer' passowrd will also required backticks I believe because it is the name of a mysql function.... SELECT * FROM table WHERE username='$username' AND `password`='$password' AND answer='$answer' Link to comment https://forums.phpfreaks.com/topic/95375-mysql-and-operator/#findComment-488435 Share on other sites More sharing options...
Thomisback Posted March 10, 2008 Share Posted March 10, 2008 Try: SELECT * FROM table WHERE userName = '$username' AND userPassword = '$password'" AND answer = '$answer'"; Link to comment https://forums.phpfreaks.com/topic/95375-mysql-and-operator/#findComment-488437 Share on other sites More sharing options...
revraz Posted March 10, 2008 Share Posted March 10, 2008 That would require him to change his fieldname. And why would you change the Case? Try: SELECT * FROM table WHERE userName = '$username' AND userPassword = '$password'" AND answer = '$answer'"; Link to comment https://forums.phpfreaks.com/topic/95375-mysql-and-operator/#findComment-488447 Share on other sites More sharing options...
Bricktop Posted March 10, 2008 Author Share Posted March 10, 2008 Hi there, neither of these seem to work - just says the credentials supplied are incorrect Any other ideas please? My code is as follows: $sql="SELECT * FROM authenti WHERE username='$username' email='$email' and password='$password'"; Thanks Link to comment https://forums.phpfreaks.com/topic/95375-mysql-and-operator/#findComment-488448 Share on other sites More sharing options...
Bricktop Posted March 10, 2008 Author Share Posted March 10, 2008 lol sry missed the "AND" working now! Thanks for all your help guys! Link to comment https://forums.phpfreaks.com/topic/95375-mysql-and-operator/#findComment-488450 Share on other sites More sharing options...
Thomisback Posted March 10, 2008 Share Posted March 10, 2008 That would require him to change his fieldname. And why would you change the Case? Try: SELECT * FROM table WHERE userName = '$username' AND userPassword = '$password'" AND answer = '$answer'"; My bad, should have been: SELECT * FROM table WHERE userName = '$username' AND Password = '$password'" AND answer = '$answer'"; Link to comment https://forums.phpfreaks.com/topic/95375-mysql-and-operator/#findComment-488453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.