当前位置: 代码迷 >> PHP >> 前辈们帮小弟我看一下下面的代码错在哪里
  详细解决方案

前辈们帮小弟我看一下下面的代码错在哪里

热度:72   发布时间:2016-04-28 18:40:16.0
前辈们帮我看一下下面的代码错在哪里
当我没有输入用户名或者密码时,为什么不能提示用户名或者密码不能为空???

<html>
<head>
<title>用户名或者密码不能为空</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form action="">
用户名:<input type="text" name="user"/></br>
密码:<input type="password" name="pass"/></br>
<input type="submit" value="登录" name="Sumbit"/></br>
<input type="reset" value="取消"/>
</form>
</body>
</html>
<?php
   if(isset($_POST['Submit'])&&$_POST['Submit']=="登录"){
   $user=$_POST['user'];
   $pass=$_POST['pass'];
       if(empty($user)||empty($pass)){
   echo "<scipt>alert('用户名或者密码不能为空');</scipt>";
   }
}
?>
   
------解决方案--------------------
echo "<scipt>alert('用户名或者密码不能为空');</scipt>";

写错了

应该是<script></script>
------解决方案--------------------
你不是 post 方式提交的,自然不能通过 $_POST 验证
------解决方案--------------------
1.form沒有加method="post"
2.<input type="submit" value="登录" name="Sumbit"/> 應該是 <input type="submit" value="登录" name="Submit"/>
3.echo "<scipt>alert('用户名或者密码不能为空');</scipt>"; 應該是 echo "<script>alert('用户名或者密码不能为空');</script>";

改成這樣就可以了
<html>
<head>
<title>用户名或者密码不能为空</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form action="" method="post">
用户名:<input type="text" name="user"/></br>
密码:<input type="password" name="pass"/></br>
<input type="submit" value="登录" name="Submit"/></br>
<input type="reset" value="取消"/>
</form>
</body>
</html>
<?php
   if(isset($_POST['Submit'])&&$_POST['Submit']=="登录"){
   $user=$_POST['user'];
   $pass=$_POST['pass'];
       if(empty($user)
------解决方案--------------------
empty($pass)){
   echo "<script>alert('用户名或者密码不能为空');</script>";
   }
}
?>
  相关解决方案