I am trying to login users but I have this error message : Fatal error: Uncaught Error: Call to a member function fetchAll() on bool
Maybe it's because the $result variable is returning 1 (bool). But I don't know how to fix this. Any help is welcome.
$sql = "SELECT * FROM users WHERE username = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("s", $_POST['name']);
$result = $stmt->execute();
print_r($result); // returns 1
$users = $result->fetchAll();
if (isset($users[0])) {
if (password_verify($_POST['password'], $users[0]->password)) {
$_SESSION['username'] = $username;
header('location: index.php');
}
else {
echo "Wrong password";
}
}
else {
echo "Wrong username";
}