How do I pass data between pages in PHP?

后端 未结 5 1472
遇见更好的自我
遇见更好的自我 2020-12-01 20:01

In a nutshell on \"page1.php\" I have a calculator that consists of an HTML form, and then the PHP code totals the input and displays the total price. Below the price, it al

5条回答
  •  无人及你
    2020-12-01 20:35

    It depends on the method attribute of your HTML form how the variables get passed to your PHP script.

    In this case, it sounds like page1.php does not have any side effect, and just passes on values, so the form on page1.php should use method=get, and the code of page2.php that reads these fields can find them in $_GET.

    The Submit button on page2.php (presumably) does have side effects on the server side, so it should use method=post, which you can read back from $_POST on the server side.

    Also, have a look at the HTML source of page2.php after filling out the first page, to see if the values are passed correctly.

提交回复
热议问题