After doing $stmt = $this->connect()->prepare(....) I keep getting $stmt->rowCount() == 0 which I don't want
class Login extends Dbh {
protected function getUser($email, $pwd) {
$stmt = $this->connect()->prepare('SELECT users_pwd FROM users WHERE users_email = ? OR users_ufname = ?;');
if(!$stmt->execute(array($email, $pwd)))
{
$stmt = null;
header("location: ../Sign_in.html?error=stmt2failed");
exit();
}
if($stmt->rowCount() == 0)
{
$stmt = null;
header("location: ../Sign_in.html?error=emailnotfound");
exit();
}
$pwdHashed = $stmt->fetchAll(PDO::FETCH_ASSOC);
$checkPwd = password_verify($pwd, $pwdHashed[0]["users_pwd"]);
if($checkPwd == false)
{
$stmt = null;
header("location: ../Sign_in.html?error=wrongpassword");
exit();
}
elseif($checkPwd == true)
{
$stmt = $this->connect()->prepare('SELECT * FROM users WHERE users_ufname = ? OR users_email = ? AND users_pwd = ?;');
if(!$stmt->execute(array($email, $email, $pwd))) {
$stmt = null;
header("location: ../Sign_in.html?error=stmt2failed");
exit();
}
if($stmt->rowCount() == 0)
{
$stmt = null;
header("location: ../Sign_in.html?error=emailsnotfound");
exit();
}
$user = $stmt->fetchALL(PDO::FETCH_ASSOC);
session_start();
$_SESSION["usersid"] = $user[0]["users_id"];
$_SESSION["usersemail"] = $user[0]["users_email"];
$stmt = null;
}
$stmt = null;
}
}
I'm trying to retrieve data from my SQL database but when I run the code and try to input the login and password details that already exist in my database, it gives me the output location: ../Sign_in.html?error=emailsnotfound, which implies that $stmt->rowCount() == 0 is true. Can someone tell me what I'm doing wrong?
from Recent Questions - Stack Overflow https://ift.tt/3FMX2bh
https://ift.tt/eA8V8J
Comments
Post a Comment