我不知道我的登录页面有什么问题。我登录后它仍然在登录页面中。
我有一个餐桌工作人员
CREATE TABLE `staff` (
`staffid` varchar(25) NOT NULL,
`password` varchar(25) DEFAULT NULL,
`staffname` varchar(50) DEFAULT NULL,
`staffemail` varchar(50) DEFAULT NULL,
`level` int(2) DEFAULT NULL,
PRIMARY KEY (`staffid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
有两个级别。1 为员工 2 为管理员 输入员工 ID 和密码后,页面应根据其级别转到页面。
1.登录.php
<? session_start(); ?>
<title>Inventory Management System</title>
<center>
<form name="form1" method="POST" action="logincheck.php">
<table width="468" height="328" border="0">
<tr>
<td height="124" colspan="2">
<?php include "header.php"?></td>
</tr>
<tr>
<td width="184" height="65"
align = "right">No Kakitangan</td>
<td width="274"><label for="staffid"></label>
<input type="text" name="staffid" id="staffid"></td>
</tr>
<tr>
<td width="184" height="60"
align = "right">Kata Laluan</td>
<td><label for="password"></label>
<input type="password" name="password" id="password"></td>
</tr>
<tr>
<td height="42" colspan="2"
align = "center"><input type="submit" name="button" id="button" value="Log In">
<input type="reset" name="button2" id="button2" value="Batal"></td>
</tr>
</table>
<p>
<input type="hidden" name="MM_insert" value="form1"/>
</p>
</form>
</center>
2.logincheck.php
<?php require_once('Connections/sqlconnection.php'); ?>
<? session_start(); ?>
<?php
$staffid = isset($_POST['staffid']) ? $_POST['staffid'] : "";
$password = isset($_POST['password']) ? $_POST['password'] : "";
//get user info from the database base on staffid and password
mysql_select_db($database_sqlconnection, $sqlconnection);
$sql = "select s.* from staff s where s.staffid = '".$staffid."' and
s.password = '".$password."'" ;
$result1 = mysql_query($sql,$sqlconnection) or die(mysql_error());
$rowUsr = mysql_fetch_array($result1);
$cnt = mysql_num_rows($result1);
$level = '';
//if staffid exists
if($cnt > 0)
{
$_SESSION['staffid']=$staffid;
$level = $rowUsr['level'];
//compare the password
if ($level == 1)
$_SESSION['userlevel']='staff';
else if ($level == 2)
$_SESSION['userlevel']='admin';
else $_SESSION['userlevel']='err';
echo "<script> location.href='index.php'; </script>";
}
else {
echo "<script> alert('Sila masukkan semula. No Kakitangan atau Kata Laluan salah.');</script>";
echo "<script> location.href='login.php'; </script>";
}
mysql_free_result($result1);
?>