I'm creating a users level login system in php & mysql. However, it leads to a white blank page. I can't figure the error. Any help is much appreciated. Thanks.
Form.html
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>MIS Electronic Request</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<br>
<form method="post" action="main.php" class="login">
<p>
<label for="login">Username:</label>
<input type="text" name="myusername" id="myusername" value="Employee id">
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="mypassword" id="mypassword" value="4815162342">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Login</button>
</p>
</form>
</body>
</html>
Main.php
<?php
session_start();
$host="localhost";
$username="root";
$password="******";
$db_name="htdocs";
$tbl_name="users";
mysql_connect("$host", "$username", "$password")or die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db("$db_name")or die("Unable to select database: " . mysql_error());
if (isset($_POST['submit']))
{
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$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($count==1){
if (user_level == 1) {
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
header("Location:Admin_home.php");
}
else if (user_level == 2) {
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
header("Location:home.php");
}
}
else {
echo "Wrong Username or Password";
}
}
?>