PHP 7.2 – Warning: count(): Parameter must be an array or an object that implements Countable

PDO fetch returns false on failure. So you need to check this case too:

if ($results && count($results) > 0 && password_verify($_POST['password'], $results['password'])) {
    $_SESSION['user_id'] = $results['id'];
    header("Location: /");
} else {
    $message = 'Sorry, those credentials do not match';
}

Leave a Comment