日期:2014-05-17 浏览次数:20413 次
<?php session_start(); include("config.php");//连接数据库 $username=$_POST['user']; $word=$_POST['password']; $userword=md5(trim($word));//MD5转换密码 $id=$_POST['user_id']; if($id=="student") { $result_psword = mysql_query("select S_PS from STUDENT where S_ID='$username'"); if(! $result_psword) echo "mysql error message:". mysql_error(); $row = mysql_fetch_assoc($result_psword); if($rows) { echo "用户不存在,请先注册"; echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);</script>"; exit; } else if($row['S_PS'] == $userword ) { $_SESSION['login']='学生'; header("Location: ../student/student.php"); }else echo "用户密码错误"; } else echo "id {$id} 不是 student";
------解决方案--------------------
mysql_query()返回的是资源集。因此不能那么判断。
if(!$result_psword)
{
echo "用户不存在,请先注册";
echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);</script>";
exit;
}
==》改为:
if(!mysql_num_rows($result_psword))
{
echo "用户不存在,请先注册";
echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);</script>";
exit;
}
------解决方案--------------------
http://dev.mysql.com/doc/refman/5.1/zh/index.html
------解决方案--------------------
判断逻辑写反了
你的
if(!$_SESSION['login']||$_SESSION['login']!='管理员'||$_SESSION['login']!='教师'||$_SESSION['login']!='学生')
表示只要有有一个成立就进入
但是,比如当 $_SESSION['login'] = '管理员' 时,
$_SESSION['login']!='教师' 和 $_SESSION['login']!='学生'
都会成立的
应写作
if(!$_SESSION['login'] || ($_SESSION['login']!='管理员' && $_SESSION['login']!='教师' && $_SESSION['login']!='学生'))