简体   繁体   中英

Why my code for login in PHP is not working?

I have tried a lot. Still it is not working. Please somebody help me to find issue in this code block. Thank you.

$email = htmlspecialchars($_POST["email"]);
$password = $_POST["password"];
$stmt = $con->prepare("SELECT * FROM users WHERE email = :email LIMIT 1");
$stmt->execute(array(':email' => $email));
$row = $stmt->setFetchMode(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0) {
    if (password_verify($password, $row['password'])) {
       echo "Valid";
    } else {
      echo "Invalid";
    }
    $stmt->close();
    $con->close();
}

try replacing

$row = $stmt->setFetchMode(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0) { ...

with

$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row!==FALSE) {...

and not sure about colon in $stmt->execute(array(' :email ' => $email));it maybe not needed there

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