Session variables?

as you can see, I have a members table with two types of users.

Here is the script to handle logins

      
if(($count==1) && ($row['type_id'] == 0))      {         
 $_SESSION['type']=$row['type_id'];          
$_SESSION['email']=$Email;                    
header( "location: admin/");         
 exit();     
 }      else if (($count==1) && ($row['type_id'] == 1))      {          

$_SESSION['type']=$row['type_id'];         
 $_SESSION['email']=$Email;                    
header( "location: index.php");          
exit();     
 }          else       {      
header("location: index.php");     
 exit();      
}   
 

First we check if the query did return 1 result and if the type is 0 (we set two session variables, then direct the user to the admin section)
Second we check if the query found a result ad the type of the user is 1, we set two sesion variables and redirect the user to the index.php page.
Lastly, if they try to login and nothing happens, they are sent to the index page

I can login as admin (type_id=0) but if I try to login as another user (type_id=1) im taken to the index page where I have

         
<?php         
if(array_key_exists('email',$_SESSION) && !empty($_SESSION['email'])) {         
?>              
<form class="navbar-form navbar-right" role="form" action="CheckLogin.php" method="post">            
<div class="form-group">             
 <input type="text" placeholder="Email" class="form-control" name="email">            
</div>            
<div class="form-group">              
<input type="password" placeholder="Password" class="form-control" name="password">            
</div>            
<button type="submit" class="btn btn-primary">Sign in</button>          
</form>          
<?php } else { ?>          
<a href="logout.php" class="btn btn-primary" role="button">Logout</a>          
<?php } ?>
'

and the form is shown (which I guess means the 2 session variables are never being set)
Why are the two session variables not being set so that only the logout link appears (instead of the form)?

(why do I lose formatting inside the php and html code blocks?)


if(!isset($_SESSION['email'])) {     
// show form
} else {
  // logout action
}

When email is set the user has authenticated therefore the logout should be shown. Otherwise, show the login form. I think your logic has revered but using isset is much simpler either way.

thanks