测试按钮不会打印出文本

时间:2016-12-09 01:42:19

标签: php html forms html-form htmlbutton

我正在尝试使用HTML按钮以PHP和HTML格式打印文本,但除了页面刷新之外,似乎没有任何其他内容。

<?php 
  if ($_POST["submit_button"]) :
    echo "testing";
    ?>
      <p>"testing"</p>
    <?php 
  endif;
?>


<html>
  <body>
    <h3>PHP button test form</h3>
    <form name="test_form" action= "" method="post">
      <button type="submit" name ="submit_button" >Update</button>
    </form>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

执行if($_POST["submit_button"])时,按钮不会显示任何值。因此,即使项目存在,此表达式也将评估为false。

您应该使用isset检查此类项是否存在。

这应该可以正常运作:

if(isset($_POST["submit_button"]))