【问题标题】:My code is not responding as i want it to be? [closed]我的代码没有像我想要的那样响应? [关闭]
【发布时间】:2013-07-18 20:21:12
【问题描述】:

我的 php 没有正确响应这是我的 HTML 代码

 <html>
<body>
<form name="myform" method="post" action="lol.php">
<input type="text" name="man" value=""> 
<input type="submit" name="submit" value= "post">
</form>
</body>
</html>

这是我的 PHP 代码

<?php 

if ($_POST['man']= null )
{print ('has no value');}
else {print ($_POST['man']);
}
?>

【问题讨论】:

  • 反应如何?
  • 你希望它如何响应?
  • 它没有给出 if 和 else 答案
  • $_POST["man"] == null not =
  • 在我看来,=== 的情况类似。

标签: php html


【解决方案1】:

使用== 运算符而不是= 进行比较,因为第二个用于赋值。

if ($_POST['man']== null )
{
print ('has no value');}
else {
print ($_POST['man']);
}

PHP Comparison Operators

【讨论】:

    【解决方案2】:

    改变

    if ($_POST['man']= null )
    

    if ($_POST['man'] == null )
    

    【讨论】:

      【解决方案3】:

      您收到任何错误消息?

      试试:

      if (isset($_POST['man'])) {
        echo $_POST['man'];
      }
      else {
        echo 'Nothing';
      }
      

      要确认一切正常,请使用:

      var_dump($_POST);
      

      你会看到$_POST上的值

      【讨论】:

        【解决方案4】:

        首先,你应该使用isset而不是=,其次也是非常重要的:=是一个赋值,但是你想要的是一个比较,所以使用==并与一个空字符串进行比较

        【讨论】:

          猜你喜欢
          • 2019-07-08
          • 1970-01-01
          • 2013-04-01
          • 2019-05-17
          • 1970-01-01
          • 2021-05-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多