title: Different access level for users and admin using php
body: <p>What am I trying to do is setup different landing pages, after login, base on access level, I am talking about PHP and MySQL of course :)</p>
  
  <p>I have a database with a users table, the users table have basically 3 fields:</p>
  
  <p><code>user,pass,access</code></p>
  
  <p>and I have 2 basics access level:</p>
  
  <p><code>(1=user, 5=admin)</code></p>
  
  <p>I found some examples online, even here, but for some reason I haven't been able to make it work. here what I got:</p>
  
  <p><code>login.php</code></p>
  
  <pre><code>&lt;form id="form" name="form" method="POST" action="login_engine.php"&gt;
  &lt;p&gt;Please enter your login information:&lt;/p&gt;
  &lt;label&gt;User&lt;/label&gt;&lt;input type="text" name="Username" id="Username" /&gt;
  &lt;label&gt;Password&lt;/label&gt;&lt;input type="password" name="Password" id="Password" /&gt;
  &lt;input name="submit" type="submit" id="submit" value="Login"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and this is the engine:</p>
  
  <pre><code>&lt;?php
  include "connect.php";
  
  // username and password sent from form
  $MyUsername = $_POST['Username'];
  $MyPassword = $_POST['Password'];
  
  
  $sql="SELECT * FROM tbl_users WHERE user=$MyUsername and pass=$MyPassword";
  $result=mysql_query($sql);
  
  $count=mysql_num_rows($result);
  
  if($count===1){
    // Register $myusername, $mypassword and redirect to file "home.php"
    session_register("user");
    session_register("pass");
    while($row = mysql_fetch_array($result))
    {
      if($row['access']=='5')
      {
        header("home1.php");
      }
      else
      {
        header("home2.php");
      }
    }
  } else {
    echo "Invalid! Please try again PC.";
    echo "&lt;br&gt;";
    echo $_POST['Username'];
    echo "&lt;br&gt;";
    echo $MyUsername;
    echo "&lt;br&gt;";
    echo $_POST['Password'];
    echo "&lt;br&gt;";
    echo $MyPassword;
    echo "&lt;br&gt;";
    echo $sql;
    echo "&lt;br&gt;";
    echo $result;
    echo "&lt;br&gt;";
    echo $count;
  }
  
  //mysql_close();
  ?&gt;
  </code></pre>
  
  <p>and this is the output:</p>
  
  <pre><code>Invalid! Please try again PC.
  userdemo
  userdemo
  mypassword
  mypassword
  SELECT * FROM tbl_users WHERE user=userdemo and pass=mypassword
  </code></pre>
  
  <p>First sign that something is wrong is that the variables $result and $count are not being printed on the error message (I had then showing some message but I changed the code so much that I lost track of what I did to make then stop showing info, but i remember that $result was showing something like "... #4" and $count was showing "0".)</p>
  
  <p>I understand that something is wrong, because its going to the end of the PHP script: the last else, but the <code>$sql</code> seems right (i might be wrong here).</p>
  
  <p>anyone have any idea what might be wrong here?</p>