<?php session_start(); 
	include('conn.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
<?php

if($_SESSION['user_chk']==""){ 
	$sql = "select * from members where user ='".$_POST['txtUser']."' and pass ='".$_POST['txtPass']."' ";
	$result = mysql_query($sql);	
	while ($user = mysql_fetch_array($result))
	{
		$chkuser=$user['user'];
		$fname=$user['fname'];
		$lname=$user['lname'];
		$level = $user['level'];
	}	
	if($_POST['txtUser']==$chkuser)
		{
			echo "<script>alert('สวัสดีคุณ ".$fname." ".$lname."')</script>";	
			$_SESSION['user_chk'] = $chkuser;
			$_SESSION['level'] = $level;
			echo "<meta  http-equiv=\"Refresh\" content=\"0;url=index.php\" />";
	}else{
		//session_destroy();
		echo "<script>alert('กรุณาตรวจสอบ Username/Password ให้ถูกต้อง')</script>";
		echo "<script>history.back();</script>";	
	}
}else {
	session_destroy();
	echo "<meta  http-equiv=\"Refresh\" content=\"0;url=login.php\" />";
}
?>
</html>