<?php
session_start();
//echo $_REQUEST['username'];
if(isset($_REQUEST['username'])){
//connection
include("connect.php");
//รับค่า user & password
$username = $_REQUEST['username'];
$password = $_REQUEST['Password'];
//query
$sql="SELECT * FROM member Where username='".$username."' and password='".$password."' ";
echo $sql;
$result = mysqli_query($condb,$sql);
if(mysqli_num_rows($result)==1){
$row = mysqli_fetch_array($result);
$_SESSION["userID"] = $row["ID"];
$_SESSION["username"] = $row["name"]." ".$row["lastname"];
$_SESSION["Userlevel"] = $row["Userlevel"];
if($_SESSION["Userlevel"]=="A"){ //ถ้าเป็น admin ให้กระโดดไปหน้า admin.php
Header("Location: admin.php");
}
if ($_SESSION["Userlevel"]=="M"){ //ถ้าเป็น member ให้กระโดดไปหน้า user.php
Header("Location: user.php");
}
}else{
echo "<script>";
echo "alert(\" user หรือ password ไม่ถูกต้อง\");";
echo "window.history.back()";
echo "</script>";
}
}else{
Header("Location: login.php"); //user & password incorrect back to login again
}
?>
ทำยังไงดีค่ะกรอก user เด้งออกแต่กรอก admin เข้าได้ โค้ตผิดรึป่าวช่วยดูหน่อยค่ะ
session_start();
//echo $_REQUEST['username'];
if(isset($_REQUEST['username'])){
//connection
include("connect.php");
//รับค่า user & password
$username = $_REQUEST['username'];
$password = $_REQUEST['Password'];
//query
$sql="SELECT * FROM member Where username='".$username."' and password='".$password."' ";
echo $sql;
$result = mysqli_query($condb,$sql);
if(mysqli_num_rows($result)==1){
$row = mysqli_fetch_array($result);
$_SESSION["userID"] = $row["ID"];
$_SESSION["username"] = $row["name"]." ".$row["lastname"];
$_SESSION["Userlevel"] = $row["Userlevel"];
if($_SESSION["Userlevel"]=="A"){ //ถ้าเป็น admin ให้กระโดดไปหน้า admin.php
Header("Location: admin.php");
}
if ($_SESSION["Userlevel"]=="M"){ //ถ้าเป็น member ให้กระโดดไปหน้า user.php
Header("Location: user.php");
}
}else{
echo "<script>";
echo "alert(\" user หรือ password ไม่ถูกต้อง\");";
echo "window.history.back()";
echo "</script>";
}
}else{
Header("Location: login.php"); //user & password incorrect back to login again
}
?>