so my PHP & PDO login is returning 0 every time, even if the info is correct. The register page works fine, no errors in that. But as soon as I try to login, it seems that $Count = $stmt->rowCount(); is returning null every time. I tried echoing $Count to see what the value was returning, and even if the information was 100% correct it still returned zero. Any help? Here's my code.
public function userLogin($email, $password)
{
try {
$dbConnection = $this->DBConnect();
$stmt = $dbConnection->prepare('SELECT * FROM `users` WHERE `email` = :email and `password` = :password');
$hash_password = hash('sha256', $password);
$stmt->bindParam(":email", $email, PDO::PARAM_STR);
$stmt->bindParam(":password", $hash_password, PDO::PARAM_STR);
$stmt->execute();
$Count = $stmt->rowCount();
$data = $stmt->fetch(PDO::FETCH_OBJ);
if ($Count == 1) {
session_start();
$_SESSION['uid'] = $data->UID;
$_SESSION['username'] = $data->username;
$_SESSION['firstname'] = $data->firstname;
$_SESSION['lastname'] = $data->lastname;
$_SESSION['ip_address'] = $data->ip_address;
header('Location: /panel/index?success');
$dbConnection = null;
return true;
} else {
header('Location: /panel/login?error');
$dbConnection = null;
return false;
}
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}