The following code allows the user to log in and direct to a particular page, or log in as an administrator and direct to another page. The user login is working, however when logging out appears undefinied variable on line 28 and 29. And if I try to log in as an administrator, in addition to not redirecting, the page is left blank.
<?php
require('config.php');
if (isset($_POST['email'])) {
$stmt = $conn->prepare("SELECT password FROM registo WHERE email=?");
$stmt->bind_param("s", $email);
$email = $_POST['email'];
$password = $_POST['password'];
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($pass);
$stmt->fetch();
if($stmt->num_rows > 0) {
if(password_verify($password,$pass)) {
$_SESSION['email'] = $email;
$_SESSION['user'] = true;
header("Location: home.php");
} else {
echo "<div class='form'>
<h3>Email/password is incorrect.</h3> <br>
Click here to <a href='memberarea.html'>Login</a>
</div>";
}
}
} else {
$ustmt = $conn->prepare("SELECT password FROM Admin WHERE email=?");
$ustmt->bind_param("s", $email);
$email = $_POST['email'];//linha 28
$password = $_POST['password']; //linha 29
$ustmt->execute();
$ustmt->store_result();
$ustmt->bind_result($pass);
$ustmt->fetch();
if($ustmt->num_rows > 0) echo "hello"; //linha 36 {
if(password_verify($password,$pass)) {
$_SESSION['email'] = $email;
$_SESSION['Admin'] = true;
header("Location: adminarea.html");
} else { //linha 47
echo "<div class='form'>
<h3>Email/password is incorrect.</h3> <br>
Click here to <a href='memberarea.html'>Login</a>
</div>";
}
} else {
echo "<div class='form'>
<h3>You are now logged out!.</h3> <br>
Click here to <a href='home.php'>Home</a>
</div>";
}
}
?>