Question

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?

Was it helpful?

Solution

You need to use AND

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top