title: My PHP Session variables aren't setting
body: <p>I need to have three different user types: guest, author, and admin.
  When the user registers, they select whether they are an author or an admin with a drop down list. The three different types have different capabilities. </p>
  
  <p>Currently, regardless of their login, it will assign guest after they login.</p>
  
  <pre><code>&lt;?php
  include("dbconnect.php");
  $con = new dbconnect();
  $con-&gt;connect();
  
  session_start();
  
  if (isset($_POST['submit']))
      {
          $sql = "SELECT type FROM Users WHERE username = '".$_POST["username"]."' AND         password = ('". sha1($_POST["password"]) ."')";
  
          $result = mysql_query($sql);
  
      if (mysql_num_rows($result) == 1) {
          $type_num=0;
          while ($info = mysql_fetch_array($result)) {
              $type =$info['type'];
          }
  
          if($type == "admin")
          {
  
              $_SESSION['type']=2;
              $_SESSION['username']= $_POST["username"];
              header("Location: viewPosts.php");
          }
          if($type == "author")
          {
  
              $_SESSION['type']=1;
              $_SESSION['username']= $_POST["username"];
              header("Location: viewPosts.php");
          }
          else 
          {
              $_SESSION['type']= $type_num;
              $_SESSION['username']="guest";
              header("Location: viewPosts.php");
          }
  
  
      } else {
          //redirect back to login form if not authorized
          header("Location: loginfailed.html");
          exit;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>How do I get it so it will assign those variables correctly??
  Thanks! </p>