我有一个用户和管理员的登录表单,我希望我的用户在登录后能被那里的名字打招呼。
我有一个名为 users 的表,其中包含以下列ID
, username
, password
, admin
,fname
lname
我有如下登录脚本代码,如果你们/gals可以提供任何帮助,因为我对php很陌生
//Connect to db
include("conndb.php");
session_start();
//Get variables from login form
$username = $_POST['username'];
$password = $_POST['password'];
echo $username;
echo $password;
$password = MD5($password);
//query to find if user and password exist and match the password.
$query = "SELECT username, admin FROM users WHERE (username = '$username' AND password
= '$password')";
$result = mysql_query($query)
or die (mysql_error($connect));
if (mysql_num_rows($result) !=1) {
$_SESSION['loginfail'] = 1;
header ('location: index.php');
}
elseif (mysql_num_rows($result) ==1)
{
// check for admin flag
$a = mysql_fetch_array($result);
if ($a[admin] == Y)
{
$_SESSION['admin'] = 1;
header('location: admin.php');
}
else
{
$_SESSION['user'] = $fname;
header('location: index2.php');
}
}