Hi There Im learning how to use prepared statements. I have figured out how to check of the password and email address match however I wish to have a criteria in the argument check also that the email address is in the system and also the check if the password does not match.
How do I add in 'IF/ELSE' argument to check the email address, then check if the password matches (which it currently does this).
Any help would be appreciated:
$emailAddress = $_POST['emailAddress'];
$password = $_POST['password'];
if ($stmt = $conn->prepare("SELECT `password` FROM `users` WHERE emailAddress=?")) {
$stmt->bind_param("s", $emailAddress);
$stmt->execute();
$stmt->bind_result($result);
$stmt->fetch();
$stmt->close();
}
if(password_verify($password, $result)){
// Login if the email and password matches
session_start();
$_SESSION['loggedin'] = true;
$_SESSION['emailAddress'] = $emailAddress;
header('Location: ../index.php');
}
else{
header('Location: ../login.php?error=1');
}
$conn->close();