I am working on login form using PDO. I have used fetch method to return the user data from database. And then use rowCount method to count the affected row and store it in count variable. But the count variable still remains zero and jump to else part of my code.
This is the login function
public function login($email, $password){
$password1 = md5($password);
$stmt = $this->pdo->prepare("SELECT 'user_id' FROM 'users' WHERE 'email' =
:email AND 'password' = :password");
$stmt->bindparam(":email", $email, PDO::PARAM_STR);
$stmt->bindparam(":password", $password1, PDO::PARAM_STR);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_OBJ);
$count = $stmt->rowCount();
if ($count > 0) {
$_SESSION['user_id'] = $user->user_id;
header('Location: home.php');
}else{
return false;
}
}
I expect to go to the home.php which I have defined in if statement.