ทำ Login โดยมีฐานข้อมูล 3 ฐานข้อมูลอ่ะคะ จะเขียนยังไงอ่ะ โดยที่ไม่แบ่ง เลเวล อ่ะ
เช็ค if else
ถ้าเข้า case ไหน ให้เขียนชื่อฐานข้อมูลลงไฟล์ แล้วไปเปิดไฟล์ตอน connect จะเข้าได้ตามฐานข้อมูลนั้นๆ
แบบนี้ใช่ไหม www.metinshop.com/store
usr:admin pass:admin
Date :
2011-03-07 17:25:12
By :
แดง
Code (PHP)
<?
session_start();
mysql_connect("localhost","root","root");
mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM member WHERE Username = '".trim($_POST['txtUsername'])."'
and Password = '".trim($_POST['txtPassword'])."'";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Username and Password Incorrect!";
}
else
{
$_SESSION["UserID"] = $objResult["UserID"];
$_SESSION["Status"] = $objResult["Status"];
session_write_close();
if($objResult["Status"] == "ADMIN")
{
header("location:admin_page.php");
}
else
{
header("location:user_page.php");
}
}
mysql_close();
?>
Go to : PHP MySQL กับ Login Form ทำระบบ User ล็อกอิน แบบง่าย ๆ ด้วย PHP และ MySQL โดยทำการตรวจสอบ Username และ Password
Date :
2011-03-07 17:25:21
By :
webmaster
คือ แบบว่า หนูมีฐานข้อมูล admin user แล้วก็ engineer อ่ะคะ
แล้วอยากให้ id ของ engineer ล๊อคอินเข้ามาแล้วเป็นหน้าของ engineer
user ล็อคอินเข้ามาเป้นหน้าของ user
แต่ใช้ฐานข้อมูลคนละตัวคะ
Date :
2011-03-07 17:49:04
By :
blooka
Date :
2011-03-07 18:11:43
By :
zoneme
ฐานข้อมูลหรือเทเบิลครับ เอาให้ชัวร์ สามฐานข้อมูลนี่มันเวอร์ไปละ
Date :
2011-03-07 18:54:34
By :
PlaKriM
คะ 3 เทเบิ้ลคะ
Date :
2011-03-07 19:14:41
By :
blooka
ใช้ if ก็ได้นะคับ
ตอนล็คออินก็เช็คว่าเป็นของตารางใหน ก็ให้ดึงตารางนั้น
Date :
2011-03-07 19:31:47
By :
petzaza009
ที่เห็นๆ ทำมีสองวิธีนะครับ
1. ใช้การสร้างตัวเลือกว่าเป็น admin, user หรือ engineer ไว้ในฟอร์มแล้วใช้ if เช็คเอาว่าจะใช้ เทเบิ้ลไหน
2. ใช้การ union table เอา ตัวอย่างที่ผมตอบไว้ แต่ไม่ได้บอกหมด เพราะคนถามไม่พยายาม เอาแต่จะขอโค๊ด https://www.thaicreate.com/php/forum/056168.html
Date :
2011-03-08 03:11:33
By :
PlaKriM
Code (PHP)
$sql = "select members.* from
(
select username, `password`, 3 as `user_type` from `member`
union
select `user` as username, `password`, 2 as `user_type` from `admin_member`
union
select `name` as username, `password`, 1 as `user_type` from `engineer`
)
as members
where username = '" . $username . "' and `password` = '" . $password . "'";
อย่างนี้ใช่ป่ะคะ
Date :
2011-03-08 12:39:39
By :
blooka
Load balance : Server 00