<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AFM ASS</title>
</head>
<?php
	session_start();
	mysql_connect("localhost","root","1234");
	mysql_select_db("afm_ass");
	$strSQL = "SELECT * FROM tb_user where Username ='".mysql_real_escape_string($_POST['txtname'])."' 
	and Password = '".mysql_real_escape_string($_POST['txtpassword'])."'";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
	if(!$objResult)
	{
									echo"<script language='JavaScript'>";
									echo"alert('ชื่อผู้ใช้ หรือ รหัสผ่านไม่ถูกต้อง');";
									echo"</script>";		
									echo "<meta http-equiv='refresh' content='0;url=index.php' />";
	}
	else
	{
			$_SESSION['User_id'] = $objResult['User_id'];
			$_SESSION['Username'] = $objResult['Username'];
			$_SESSION['Password']= $objResult['Password'];
			$_SESSION['Usertype_id']= $objResult['Usertype_id'];

			
			if($objResult["Usertype_id"] == "1")
			{
				header("location:Mainpage.php");
			}
			else
			{
				header("location:Mainpage.php");
			}
	}
	mysql_close();
?>
</html>