简体   繁体   中英

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:

$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.

Make sure the username and password variables are correctly named both in your php code and the database. Capitalizations matter!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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