I need to redirect users to two (2) different pages based on the roles given to them in the database. Only the email and password is submitted on the login page. I have to fetch the role from the database which looks like this:
Email | Password | UserType
aa@me.com xxxxxx System User
bb@me.com xxxxxx Administrator
And here is what I have done so far:
<?php
session_start();
error_reporting(0);
include('includes/dbconnection.php');
if(isset($_POST['login']))
{
$email=$_POST['email'];
$password=md5($_POST['password']);
$query=mysqli_query($con,"select ID from gts_users where Email='$email' && Password='$password' ");
$ret=mysqli_fetch_array($query);
$count=mysqli_num_rows($query);
if($ret==1){
$_SESSION['detsuid']=array(
'Email'=>$ret['email'],
'Password'=>$ret['password'],
'UserType'=>$ret['role']
);
$role=$_SESSION['detsuid']['ID'];
switch($role){
case 'System User':
header('location: dashboard.php');
break;
case 'Administrator':
header('location: admin/index.html');
break;
}
}else{
echo "<script type='text/javascript'>alert('Wrong email and password combination');
</script>";
}
}
?> <form action="" method="post"> <input type="email" placeholder="E-mail" name="email"> <input type="password" name="password" placeholder=" Password"> <button type="submit" value="login" name="login">Login</button> </form>