解决方案 »

  1.   

    如果这是全部代码,$_POST['username']和$_POST['passwd']也会报错。
      

  2.   

    print_r($_POST);
    看一下post的数据有哪些
      

  3.   

    其他代码我打了省略号全部代码太多了
    我试过改成$role =“teacher”;结果就正常。
    应该是$role = $_POST['role'];取不到表单中的值,但我不知道怎么改。
    也试过把name值换一个也不行
      

  4.   

    你在第一行打印一下print_r($_POST);看看有没有role这一项
      

  5.   

    Array ( [username] => student [passwd] => 123456 )
    没有select中的值  
    我的select写错了吗?
      

  6.   

    页面有js处理么,是不是被js影响了。
    print_r($_POST); 就知道提交了哪些
      

  7.   

    没有js
    Array ( [username] => student [passwd] => 123456 )
    没有 role  。。
      

  8.   

    Array ( [username] => student [passwd] => 123456 )
    没有select中的值  
    我的select写错了吗?
    你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
      

  9.   

    Array ( [username] => student [passwd] => 123456 )
    没有select中的值  
    我的select写错了吗?
    你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
    那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?
      

  10.   

    Array ( [username] => student [passwd] => 123456 )
    没有select中的值  
    我的select写错了吗?
    你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
    那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?
    name名相同?你怎么没贴出来
      

  11.   

    Array ( [username] => student [passwd] => 123456 )
    没有select中的值  
    我的select写错了吗?
    你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
    那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?
    name名相同?你怎么没贴出来
    。。全贴出来
    index2.php
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>登陆模块</title>
    </head>
    <fieldset>
         <legend>loading</legend>
            <form method="post" action="lib\ChkLogin.php">
         <table>
                <tr>
                <td>username:</td>
                <td><input type="text" name="username" /></td>
                </tr>
                <tr>
                <td>password:</td>
                <td><input type="password" name="passwd" /></td>
                </tr>
                <tr><td>your role:</td>
                <td>
                <select name="role">
                 <option value="student">student</option>
                    <option value="teacher">teacher</option>
                </select>
                </td>
                </tr>
                <tr>
                <td><input type="submit" value="ok" /></td>
                <td><input type="reset" value="no" /></td>
                </tr>
            
            </table>
            </form>
        </fieldset>
    <body>
    </body>
    </html>ChkLogin.php
    <?php
    $username = $_POST['username'];
    $passwd = $_POST['passwd'];
    $role = $_POST['role'];
    print_r($_POST);
    if($username==""||$passwd==""){
    echo "<script>";
    echo "alert(\"用户名或密码不能为空!\");";
    echo "location.href=\"../index2.php\";";
    echo "</script>";
    }
    else{
    include("dbhelper.php");
    if($role=="teacher"){
    $helper = new dbhelper();
    if($helper ->open()){
    $row = mysql_fetch_array(mysql_query("select * from teacher where username='$username'"));
    }
    $helper ->close();
    if($row["password"]==$passwd){
    header("location:../teacher.php");
    }
    else{
    echo "<script>";
    echo "alert(\"用户名或密码错误!\");";
    echo "location.href=\"../index2.php\";";
    echo "</script>";
    }
    }
    else if($role=="student"){
    $helper = new dbhelper();
    if($helper ->open()){
    $row = mysql_fetch_array(mysql_query("select * from student where username='$username'"));
    }
    $helper ->close();
    if($row["passwd"]==$passwd){
    header("location:../student.php");
    }
    else{
    echo "<script>";
    echo "alert(\"用户名或密码错误!\");";
    echo "location.href=\"../index2.php\";";
    echo "</script>";
    }
    }
    }
    ?>
      

  12.   

    我只是把 <form method="post" action="lib\ChkLogin.php">改成<form method="post" action="lib/ChkLogin.php">也就是斜线改一下,我这里可以传过去
      

  13.   

    第5行的print_r($_POST); 没有role?
      

  14.   

    其实我很想知道LZ你如果没有role,那为什么第四行的$role = $_POST['role'];不报错。。
    或者你先把php页面和html页面放到一起,别让action查找路径试试
      

  15.   

    html 代码为什么不写在body里面