dimanche 31 mai 2020

Not having successful login to my account

I'm trying to login to my account., but after entering the correct password, the server is echoing wrong password. I'm not sure if the error is near the if-else condition.

<?php
 session_start();
//Database Configuration File
include('database.php');
error_reporting(1);
if(isset($_POST['submit']))
  {
    // Getting username/ email and password
    $email=$_POST['email'];
    $password=$_POST['password'];
    // Fetch data from database on the basis of username/email and password
    $sql ="SELECT email FROM student WHERE (email=:email)";
    $query= $conn -> prepare($sql);
    $query-> bindParam(':email', $email, PDO::PARAM_STR);
    $query-> execute();
    $results=$query->fetchAll(PDO::FETCH_OBJ);
if($query->rowCount() > 0)
{
foreach ($results as $row) {
$passwordhash=$row->password;
}
//verifying Password
if (password_verify($password, $passwordhash)) {
$_SESSION['email']=$_POST['email'];
    echo "<script type='text/javascript'> document.location = 'studentdashboard.php'; </script>";
  } else {
echo "<script>alert('Wrong Password');</script>";
  }
}
//if username or email not found in database
else{
echo "<script>alert('User not registered with us');</script>";
  }
}
?>

Aucun commentaire:

Enregistrer un commentaire