I am making a e book website. after making a register and muti user login page, it shoud be directed to userhome page or adminhome page but instead it keeps telling me that my email and password dont match. I have connected it to database where entries are there. How can i solve it?
This is my login page.
<?php
@include 'config.php';
if(isset($_POST['submit'])){
$email = mysqli_real_escape_string($conn, $_POST['email']);
$pass = md5($_POST['password']);
$select_users = mysqli_query($conn, "SELECT * FROM `users` WHERE email = '$email' AND password = '$pass'") or die('query failed');
if(mysqli_num_rows($select_users) > 0){
$row = mysqli_fetch_array($select_users);
if($row['user_type'] == 'admin'){
$_SESSION['admin_name'] = $row['name'];
$_SESSION['admin_email'] = $row['email'];
$_SESSION['admin_id'] = $row['id'];
header('location:admin_page.php');
}elseif($row['user_type'] == 'user'){
$_SESSION['user_name'] = $row['name'];
$_SESSION['user_email'] = $row['email'];
$_SESSION['user_id'] = $row['id'];
header('location:home.php');
}
}else{
$message[] = 'email and password dont match ';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>login</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<!-- custom css file link -->
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
if(isset($message)){
foreach($message as $message){
echo '
<div class="message">
<span>'.$message.'</span>
<i class="fas fa-times" onclick="this.parentElement.remove();"></i>
</div>
';
}
}
?>
<div class="form-container">
<form action="" method="post">
<h3>login now</h3>
<input type="email" name="email" placeholder="enter your email" required class="box">
<input type="password" name="password" placeholder="enter your password" required class="box">
<input type="submit" name="submit" value="login now" class="btn">
<p>don't have an account? <a href="register.php">register now</a></p>
</form>
</div>
</body>
</html>