简体   繁体   English

SQL语句出现问题-使用PHP查询数据库

[英]Trouble with SQL statements - querying databases with PHP

I'm trying to write some code that will connect to a database called 'user' and find data from the 'password' field. 我正在尝试编写一些代码,这些代码将连接到名为“用户”的数据库并从“密码”字段中查找数据。 I've got this PHP written so far: 到目前为止,我已经编写了以下PHP:

$passw = $_POST['pass'];
$user = $_POST['user'];
$users_password_db = "SELECT password FROM 'user' WHERE username=$user";

$result = $mysqli->query($users_password_db);
if ($passw != $result){
    $errors[] = "Incorrect username or password. Please try again, or contact the admin for    support.";
 }
else {
  header('Location: /dashboard.php');
   }

However, every time I log in with my correct username and password, it says that the password is wrong. 但是,每次我使用正确的用户名和密码登录时,都会显示密码错误。 I don't think this is a connection error, since I can add data into the database okay. 我不认为这是连接错误,因为我可以将数据添加到数据库中。

I'm just beginning with SQL, so sorry if this is an obvious question. 我只是从SQL开始,所以很抱歉,如果这是一个明显的问题。

Make sure the username and password variables are correctly named both in your php code and the database. 确保用户名和密码变量在您的php代码和数据库中均正确命名。 Capitalizations matter! 大写很重要!

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

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