I have tried many times but every time its says Email & Password Not Matched!
.I can not find any solution of it.I have used PDO for database connection.I think i have problem with session value.But i can not find the error.I have tried so far:
<?php
/* For Login */
include 'db.php';
if (isset($_POST['login'])) {
$email = $_POST['email'];
$hash = $_POST['password'];
$password = password_hash($hash, PASSWORD_DEFAULT);
$records = $db->prepare("SELECT id FROM users WHERE email=? AND password=?");
$records->execute(array($email,$password));
$userdata = $records->fetch(PDO::FETCH_ASSOC);
if (!empty($email) && !empty($hash)) {
if (count($userdata)>0 ) {
//session_start();
$_SESSION['email'] = $userdata['email'];
$_SESSION['password'] = $userdata['password'];
if ($_POST['password'] == $userdata['password']) {
echo "<div class='alert alert-success text-center'>
<strong>Successfully</strong> Login</div>";
exit;
}else{
echo "<div class='alert alert-danger text-center'>
<strong>Email & Password</strong> Not Matched!
</div>";
}
}else{
echo "Email and Password Not Matched!";
echo $_SESSION['email'];
}
}else{
echo "<div class='alert alert-danger text-center'>
<strong>Email & Password</strong> must not be empty!</div>";
}
}
?>
Thanks in advance.