Mysql“where”和“or”语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6561311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql "where" and "or" statement
提问by Ryan
I started to work on a Mysql query abut it keeps coming up with a error?
我开始处理 Mysql 查询,但它不断出现错误?
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?
这意味着它没有找到任何人。这意味着我的查询是错误的?
回答by Tudor Constantin
The ... OR SELECT...
is giving the error. I think you are trying to write that as:
该... OR SELECT...
是给错误。我认为您正在尝试将其写为:
$query = ("select * from `users` where (`username`='$username' OR `$username `='$email') and `password`='$password'");
回答by Harry Joy
Try this query:
试试这个查询:
select * from `users`
where
(`username`='$username' or `username `='$email') and `password`='$password'
回答by Peter Bern Thomsen
Works!
作品!
SELECT * FROM "users" WHERE (username = '".$username."' OR username = '".$email."') AND password = '".$password."'";