登录代码工作不正常


login code not working properly

我的应用程序使用了登录名。。首先,我只使用管理员登录,它运行得很好,但现在当我添加教师和学生登录时,我发现了一个问题,它没有登录我的客栈。,,但只是重定向到未经授权的访问请求帮助

login.php

<?php include("../includes/config.php");?>
<!DOCTYPE HTML>
<html>
<head>
<title>Admdin Login</title>
</head>
<body>
    <form method="post" action="login-action.php">
    <label>User Name:</label> <input type="text" name="un" />
    <label>Password:</label> <input type="password" name="pd" />  <br /><br />
    <input type="submit" value="Login" />
</form>
<a href="forgot-password.php">Forgot Password?</a>
</body>
</html>

这是login-action.php

<?php include("../includes/config.php");?>
<?php
$uid=$_POST["un"];
$pwd=$_POST["pd"];
$encpwd=md5($pwd);
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$result = mysql_query("SELECT * FROM accounts WHERE (email='".$uid."' AND   password='".$encpwd."')");
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
while($row = mysql_fetch_array($result))
{
   $_SESSION['firstname'] = $row['firstname'];
   $_SESSION['lastname'] = $row['lastname'];
   $_SESSION['type'] = $row['type'];
   $_SESSION['id'] = $row['id'];
   $_SESSION['email'] = $row['email'];
   $_SESSION["loggedin"]=true;
}
}
else {
 $_SESSION["loggedin"]=false;
}
mysql_close($con);
if ($_SESSION["loggedin"])
{
if ($_SESSION["type"]=="A")
    {
        $_SESSION["isadmin"]=true;
    }
if ($_SESSION["type"]=="T")
    {
        $_SESSION["isteacher"]=true;
    }
if ($_SESSION["type"]=="S")
     {
         $_SESSION["isstudent"]=true;
     }
 }
if ($_SESSION["isadmin"])
{
header("Location: $fullpath"."admin/000.php");
}
if ($_SESSION["isteacher"])
{
header("Location:$fullpath"."teacher/");
}
if ($_SESSION["isstudent"])
{
header("Location:$fullpath"."student/");
}
else {
   header("Location: $fullpath"."login/unauthorized.php");
}
?>
    if ($_SESSION["isadmin"])
    {
        header("Location: $fullpath"."admin/000.php");
    }
    elseif ($_SESSION["isteacher"])
    {
        header("Location:$fullpath"."teacher/");
    }
    elseif ($_SESSION["isstudent"])
    {
        header("Location:$fullpath"."student/");
    }
    else {
        header("Location: $fullpath"."login/unauthorized.php");
    }