我不知道我的登录页面有什么问题。登录后,它仍然在登录页面中。
我有一个工作人员
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
有两个级别。输入staffid和密码后,管理员2为管理员2,页面应该在他们的级别上进入页面。
1.login.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);
?>
答案 0 :(得分:0)
您需要将内部结果指针移动到mysql_data_seek的开头。尝试使用:
mysql_data_seek($result1, 0);
使用:
$rowUsr = mysql_fetch_array($result1);
mysql_data_seek($result1, 0);
$cnt = mysql_num_rows($result1);
发生的事情是,一旦执行mysql_fetch_array
,指针就会留在数据集的末尾。 mysql_data_seek($result1, 0);
会将其返回到开头。