Ryan
Ryan

Reputation: 135

Mysql "where" and "or" statement

I started to work on a Mysql query abut it keeps coming up with a error?

can some one look at it and tell me what i am doing wrong?

$query = ("select * from `users` where (`username`='$username' and `password`='$password' or select * from `users` where `$username `='$email' and `password`='$password')");

the error is

 mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a8423624/public_html/testchecklogin.php on line 57

which means that it hasn't found anyone. This means that my Query is wrong?

Upvotes: 12

Views: 54548

Answers (3)

Peter Bern Thomsen
Peter Bern Thomsen

Reputation: 79

Works!

SELECT * FROM "users" WHERE (username = '".$username."' OR username = '".$email."') AND password = '".$password."'";

Upvotes: 1

Tudor Constantin
Tudor Constantin

Reputation: 26871

The ... OR SELECT... is giving the error. I think you are trying to write that as:

$query = ("select * from `users` where (`username`='$username' OR `$username `='$email') and `password`='$password'");

Upvotes: 24

Harry Joy
Harry Joy

Reputation: 59694

Try this query:

select * from `users` 
where 
(`username`='$username' or `username `='$email') and `password`='$password'

Upvotes: 3

Related Questions