title: how to check the permission and send the user to the correct page in php?
body: <p>Halo everyone, I got a question for how to check the permission when the user login and send the user to the page where they suppose to be. But I just can't make it. Can anyone help?</p>
  
  <pre><code>&lt;?php
  
  $host="localhost"; // Host name
  $username="root"; // Mysql username
  $password="123456789"; // Mysql password
  $db_name="hospital_db"; // Database name
  $tbl_name="members"; // Table name
  
  // Connect to server and select databse.
  mysql_connect("$host", "$username", "$password")or die("cannot connect");
  mysql_select_db("$db_name")or die("cannot select DB");
  
  // username and password sent from form
  $myusername=$_POST['myusername'];
  $mypassword=$_POST['mypassword'];
  
  // To protect MySQL injection (more detail about MySQL injection)
  $myusername = stripslashes($myusername);
  $mypassword = stripslashes($mypassword);
  $myusername = mysql_real_escape_string($myusername);
  $mypassword = mysql_real_escape_string($mypassword);
  
  $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  $result=mysql_query($sql);
  
  // Mysql_num_row is counting table row
  $count=mysql_num_rows($result);
  
  // If result matched $myusername and $mypassword, table row must be 1 row
  if($count==1){
  $permissionssql="SELECT permissions FROM $tbl_name WHERE permissions";
  $permissionssqlresult=mysql_query($permissionssql);
  if(permissions==admin){
  header("location:admin.php");
  
  if(permissions==employees){
  header("location:employees.php");
  
  if(permissions==employees){
  header("location:otherstaff.php");
  }
  }
  }
  }
  else{
  echo "Wrong username or password!";
  }
  
  ?&gt;
  </code></pre>
  
  <p>I create a permissions on my table and it is vachar.
  The permission have admin/employees/otherstaff.
  I'm just trying to let the system send the user to the correct page but it always doesnt work.
  I'm really appreciate if there's an answer.
  thanks</p>