<?php
session_start();
?>
<!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>
<body>
<?php
header("Content-Type:text/html;charset=UTF-8");
//连接数据库
mysql_connect("localhost","root","");
mysql_select_db("db12");
/**该文件的作用是 接收用户输入的信息,进行查询,判断是否存在,如果存
在则跳转到成功页面,如果错误,则给出错误提示。*/
//接受用户参数(用户名、密码)
$user=$_POST['username'];
$pass=$_POST['password'];
//根据用户名进行查询,取出密码
$sql="select password from tb_user where username='".$user."'";//执行查询
$rs=mysql_query($sql);
if($rs!=""){
$selpass=mysql_result($rs,0);
}
if($selpass!=''){ 
   //判断取出的密码是否和用户输入的一致
     if($pass==$selpass){
     $_SESSION['username']=$user;
 ?>
     <script>
     //如果一致提示登陆成功
 alert("登陆成功!");
 //页面要跳转到主页
 location.href="index.php";
 </script>
 <?php
     }else{
 //提示密码错误
 ?>
     <script>
     //如果一致提示登陆成功
 alert("密码输入错误,再想想!");
 //页面要跳转到主页
 location.href="login.php";
 </script>
 <?php
 }
}else{
//如果根据用户名查询不到信息,提示用户名不存在
     ?>
     <script>
     //如果一致提示登陆成功
 alert("您输入的用户名不存在,请核实!");
 //页面要跳转到主页
 location.href="login.php";
 </script>
   <?php
}
 ?>
</body>
</html>
上面是写的处理用户登录的代码,
为什么在登陆界面无论输入正确的还是错误的信息都显示这个:

解决方案 »

  1.   

    $user=$_POST['username'];
    $pass=$_POST['password'];确认你的程序是从表单提交进入的
    确认你的表单是 post 方式的
    确认控件名没有错
      

  2.   

    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <table width="336" height="193" border="0" align="center" bgcolor="#009933">
      <tr>
        <td height="157"><form id="form1" name="form1" method="post" action="1.php">
          <p>&nbsp; 用户
            <input type="text" name="username" />
          </p>
          <p>&nbsp;&nbsp; 密码
            <input type="text" name="password" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
        </form>
          <table width="271" height="33" border="0">
            <tr>
              <td><form id="form2" name="form2" method="post" action="1.php">
                <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                <input type="submit" name="Submit" value="登录" />
                  </label>
              </form>
              </td>
              <td><form id="form3" name="form3" method="post" action="">
                <label>&nbsp;&nbsp; 
                <input type="submit" name="Submit2" value="重置" />
                  </label>
              </form>
              </td>
            </tr>
          </table></td>
      </tr>
    </table>
    这个是登陆的表单
    然后之前发的是处理表单的代码,
    出错页就是之前那个处理代码那个文件
      

  3.   

    要那么多form干什么,一个form就可以了。
      

  4.   

    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <table width="336" height="193" border="0" align="center" bgcolor="#009933">
      <tr>
        <td height="157"><form id="form1" name="form1" method="post" action="1.php">
          <p>&nbsp; 用户
            <input type="text" name="username" />
          </p>
          <p>&nbsp;&nbsp; 密码
            <input type="text" name="password" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>      <table width="271" height="33" border="0">
            <tr>
              <td>
                <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                <input type="submit" name="Submit" value="登录" />
                  </label>
              </td>
              <td>
                <label>&nbsp;&nbsp; 
                <input type="submit" name="Submit2" value="重置" /> //此处type改为reset是否更为合适?
                  </label>
              </form>
              </td>
            </tr>
          </table></td>
      </tr>
    </table>
      

  5.   

    print_r()你的用户名密码 不就知道怎么回事吗!
      

  6.   

    重置总不能跟前面放在一个form里面吧这不是重点啦
      

  7.   

    为什么不能?你的第二个form里面根本就没有username 和 password 的控件,当然就报错了。
    print_r($_POST);  就清楚了