1st post here so forgive me if i made any errors when creating the post. I have the following code in which i want to redirect users when they login based on their user_type. I have the following code but i'm quite unsure how to do that.
<?php
session_start();
if(isset($_SESSION['user_type']) == "S") {
header("Location: /main/studenthome.php");
}
else if(isset($_SESSION['user_type']) == "A") {
header("Location: /main/staffhome.php");
}
include_once 'dbconnect.php';
//check if form is submitted
if (isset($_POST['login'])) {
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$result = mysqli_query($con, "SELECT * FROM users WHERE username = '" . $username. "' and password = '" . md5($password) . "'");
if ($row = mysqli_fetch_array($result)) {
$_SESSION['usr_id'] = $row['usrId'];
$_SESSION['usr_name'] = $row['username'];
$_SESSION['user_type'] = $row["usertype"];
header("Location: /main/studenthome.php");
}
} else {
echo "<div class= 'col-md-4 col-md-offset-4 well' >
Incorrect <font color = '#de615e'> Username </font> or <font color = '#de615e'> Password </font>. Please try again
</div>";
}
}
?>
Thanks for your time