Use $_POST to get input values on the same page

前端 未结 1 503
孤街浪徒
孤街浪徒 2020-12-10 08:46

Sorry if this is a rather basic question.

I have a page with an HTML form. The code looks like this:

相关标签:
1条回答
  • 2020-12-10 08:59

    Put this on a php file:

    <?php
      if (isset($_POST['submit'])) {
        $example = $_POST['example'];
        $example2 = $_POST['example2'];
        echo $example . " " . $example2;
      }
    ?>
    <form action="" method="post">
      Example value: <input name="example" type="text" />
      Example value 2: <input name="example2" type="text" />
      <input name="submit" type="submit" />
    </form>
    

    It will execute the whole file as PHP. The first time you open it, $_POST['submit'] won't be set because the form has not been sent. Once you click on the submit button, it will print the information.

    0 讨论(0)
提交回复
热议问题