I need some help trying to figure out why my php login redirect isnt functioning properly. I first attempted just a simple login and it worked fine. but after I added an if statement to redirect according to their user level, it just crashes.
here's the code:
*edit: i need more help with the code actually redirecting to the corresponding page of the user's role level. Currently, im able to log in (no login errors) but it does not send the user to the their corresponding page (ie: admin to the admin page, user to the the user page, and coordinator to the coordinator page).
<?php
session_start();
include 'connect.php';
$email = $_POST["login_email"];
$pwd= $_POST["login_pwd"];
$role = $_POST["role"];
$sql = "SELECT * FROM users WHERE email='$email' AND password= '$pwd' AND role='$role' ";
if($row != mysqli_fetch_assoc($result)){
echo "Your user name or password is incorrect!";
header("Location:login.html");
}else{
$_SESSION['id'] = $row['id'];
if ($_SESSION['role'] == 'admin') {
header("Location: admin.php");
} else if ($_SESSION['role'] == 'editor') {
header("Location: editor.php");
} else if ($_SESSION['role'] == 'user') {
header("Location: user.php");
}
echo "Successful login!";
}