douzi1991 2012-10-24 08:16
浏览 62
已采纳

如果是设置$ _POST

I have a form on one page that submits to another page. There, it checks if the input mail is filled. If so then do something and if it is not filled, do something else. I don't understand why it always says that it is set, even if I send an empty form. What is missing or wrong?

step2.php:

<form name="new user" method="post" action="step2_check.php"> 
    <input type="text" name="mail"/> <br />
    <input type="password" name="password"/><br />
    <input type="submit"  value="continue"/>
</form>

step2_check:

if (isset($_POST["mail"])) {
    echo "Yes, mail is set";    
} else {    
    echo "N0, mail is not set";
}
  • 写回答

14条回答 默认 最新

  • dongzhong8691 2012-10-24 08:19
    关注

    Change it to this:

    if (isset($_POST["mail"]) && !empty($_POST["mail"])) {
        echo "Yes, mail is set";    
    } else {  
        echo "N0, mail is not set";
    }
    

    So $_POST is always set, but its content might be empty.

    Since !empty() already checks whether the value is set, you can also use this version:

    if (!empty($_POST["mail"])) {
        echo "Yes, mail is set";    
    } else {  
        echo "N0, mail is not set";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(13条)

报告相同问题?

悬赏问题

  • ¥15 c++ gmssl sm2验签demo
  • ¥15 关于模的完全剩余系(关键词-数学方法)
  • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
  • ¥15 关于移动机器人坐标计算
  • ¥30 模拟电路 logisim
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音