PHP Login with redirect depending on level

I have this code which should let users be redirected to a specific page depending on their access level (U_YearID) but all i get bk is a blank page when i click login button on the form.

any ideas what it could be?

<?php
session_start(); 
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
$host="localhost"; // Host name
$username="phpuser"; // username
$password="phpuser"; // password
$db_name="phpsite"; // Database name
$tbl_name="users"; // Table name
 
// Replace database connect functions depending on database you are using.
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");

//submitting query
// username and password sent from form
//NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection!
$UsersID=mysql_real_escape_string($_POST['UsersID']);
$U_Password=mysql_real_escape_string($_POST['U_Password']);

$sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'";
//echo $sql;
$result=mysql_query($sql);

//checking results
// Replace counting function based on database you are using.
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

//Direct Userbased on result
if($count==1){
  // Register $UsersID, $U_Password and redirect to file "login_success.php"
  $_SESSION['UsersID']=$result[0];
  $_SESSION['U_YearID']=$result[1];
  if($_SESSION['U_YearID']==1)  
  header("location:login_success.php");
  if($_SESSION['U_YearID']==2)
  header("location:login_success2.php");
  if($_SESSION['U_YearID']==4)
  header("location:login_success4.php");
} else {
 
  echo "Wrong Username or Password";
}
?>

Try echoing out the U_YearID - just to check if the value is one you are expecting.

[php]echo $result[1];[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service