<?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'");
/*while ($rows=mysql_fetch_array($result_psword)){}*/
if(!$result_psword)
{
echo "用户不存在,请先注册";
echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);</script>";
exit;
}
else if($result_psword==$userword)
{

$_SESSION['login']='学生';
echo "<script>window.location.href='../student/student.php';</script>";
}
}
登录后发现没有跳转,直接停在login.php页面里。
$username,$userword,$id都测试了有传进去值,我想就是
$result_psword=mysql_query("select S_PS from STUDENT where S_ID='$username'");
这句的问题了。
$reslt_psword我想测试里面的值都测试不出来,这个里面到底包含着什么东西?
($result_psword==$userword)这句话直接判断为什么会不行?
做毕设中,分不敢给多啊··留点以后用。

解决方案 »

  1.   

    <?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()和mysql_fetch_* 各种情况下的返回值
      

  2.   

    I'm so sorry! 我写反了一些逻辑。
    这段代码才算正确
    $result_psword = mysql_query("select S_PS from STUDENT where S_ID='$username'");
    // 如果 SQL语句出错
    if( $result_psword === false) 
       echo "mysql error message:". mysql_error();$row = mysql_fetch_assoc($result_psword);
       // 如果$row为空,即没有匹配的用户
       if( ! $row ) {
          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 "用户密码错误";
      

  3.   

    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;
    }
      

  4.   

    http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  5.   

    <?php
    session_start();
    if(!$_SESSION['login']||$_SESSION['login']!='管理员'||$_SESSION['login']!='教师'||$_SESSION['login']!='学生')
    {
    echo "无权限进入此页面!";
    echo "<script>setTimeout(function(){window.location.href='../index.php'}, 3000);</script>";
    exit;
    }
    ?>
    现在可以跳转进去了,可是在student.php却提示无权限,这段代码又哪里有问题了?
    谢各位大大··
      

  6.   

    判断逻辑写反了
    你的
    if(!$_SESSION['login']||$_SESSION['login']!='管理员'||$_SESSION['login']!='教师'||$_SESSION['login']!='学生')
    表示只要有有一个成立就进入
    但是,比如当 $_SESSION['login'] = '管理员' 时,
    $_SESSION['login']!='教师' 和 $_SESSION['login']!='学生'
    都会成立的
    应写作if(!$_SESSION['login'] || ($_SESSION['login']!='管理员' && $_SESSION['login']!='教师' && $_SESSION['login']!='学生'))
      

  7.   

    array mysql_fetch_array ( resource $result [, int $ result_type ] )
    返回根据从结果集取得的行生成的数组,如果没有更多行则返回 FALSE。