简体   繁体   English

mysql-为“ WHERE”条件设置多个值

[英]mysql - Set more than one value for 'WHERE' condition

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? 问题是查询总是失败,那么如何解决“ WHERE ”条件?

您需要使用AND

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

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 . 如果要匹配,则应使用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. 您需要使用AND来分隔您的条件。

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

Also, be aware that coding this way may make you vulnerable to SQL injection bugs/attacks. 另外,请注意,以这种方式进行编码可能会使您容易受到SQL注入错误/攻击的攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM