I am trying to create two separate sessions- one for if the user is admin and another if the user is author. $type stored type as enum (can be either author or admin). But my code is creating author session even for admin. I am new to PHP and MySQL . can somebody tell me where the error is in my code.
<?php
include("dbconnect.php");
$con= new dbconnect();
$con->connect();
//create and issue the query
$sql = "SELECT type FROM users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";
$result = mysql_query($sql);
//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {
   $type_num=0;
    //if authorized, get the values
      while ($info = mysql_fetch_array($result)) {
    $type =$info['type'];
    }
     if($type == "admin")
        {
         $_SESSION['type']=1;
         $u = 'welcome.php';
         header('Location: '.$u);  
        }
       else
        {
          $_SESSION['type']=$type_num;
          $u = 'welcome.php';
          header('Location: '.$u);
        }
    } 
      else {
        //redirect back to loginfailed.html form if not in the table
        header("Location: loginfailed.html");
        exit;
        }
        ?>
My welcome.php is as below
<?php
  session_start();
?>
<html>
<body>
<h2>Welcome.</h2>
<?
if($_SESSION['type']==1){
     echo "You are of the usertype Admin and your session id is ";
     echo session_id();
}
else {
echo "You are of the usertype Author and your session id is ";
echo session_id();
}
?>
</body>
</html>
Thank You so much in advance.
 
     
     
     
    