<?php
if(isset($_POST['username'])){
$user = strtolower(trim($_POST['username']));
$pass = trim($_POST['password']);
$sql = "select * from user_admin as u where u.username='$user' and u.password='$pass' ";
$dbquery = mysqli_query($connect,$sql);
$result1 = mysqli_fetch_array($dbquery);
if($result1){
$_SESSION['name']=$result1['name'];
$_SESSION['admin']=1;
$_SESSION['admin_level']=$result1['level'];
//echo "<script>window.location='index.php';</script>";
header("Location: index.php");
}else{
echo "<script>alert(' หรือ รหัสผ่าน ไม่ถูกต้อง'); document.location.href='index.php?try=1';</script>";
}
}
?>