mysql - Set more than one value for 'WHERE' condition

155 Views Asked by At

I have the following query:

  $select_query = "SELECT * FROM users WHERE userName='$user_name', password='$password'";

The problem is that the query always fail, so how can I fix the 'WHERE' condition?

3

There are 3 best solutions below

0
cmorrissey On BEST ANSWER

You need to use AND

$select_query = "SELECT * FROM users WHERE userName='$user_name' AND password='$password'";
0
Bart Friederichs On

You'll need boolean logic for it:

$select_query = "SELECT * FROM users WHERE userName='$user_name' AND password='$password'";

Of course, this assumes you want the username and password to match. If you want either to match, you should use OR. This is all quite basic database stuff. Please read the documentation or get yourself a good book.

3
Steven Mastandrea On

you need to use AND to separate your conditions.

where username ='$user_name' and password='$password'

Also, be aware that coding this way may make you vulnerable to SQL injection bugs/attacks.