I just started to learn PHP and encountered difficulties when learning how to submit data through forms. Please give me some advice.
I learned it from the tutorials in these two places: RUNOOB, W3C
The problem is this, there is a form in the index.php page, use post to submit the data and then jump to the Test13_welcome.php page and enter This page gets the data, but it seems that it is possible to follow online tutorials, but it is really not possible here. The detailed description is as follows:
System: Mac OSX 10.11.5
IDE: PHPStorm 2016.1.2
PHP: 7.0.7
Browser: Safari and Chrome have been tried
The following is index.php
<code><html> <head> </head> <body> <form action="Test13_welcome.php" method="post" enctype="application/x-www-form-urlencoded"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit" name="submit"> </form> </body> </html></code>
The following is Test13_welcom.php
<code><html> <body> <?php var_dump($_REQUEST); var_dump($_POST); $a = file_get_contents('php://input', 'r'); echo $a.PHP_EOL; echo "<br>"; ?> Welcome : <?php echo $_POST["name"]; ?><br> Your email address is : <?php echo $_POST["email"]; ?> </body> </html></code>
After running, enter any data and the result will be displayed after the jump:
<code>array(0) { } array(0) { } name=234&email=2345&submit=%E6%8F%90%E4%BA%A4 Welcome : Notice: Undefined index: name in /Users/JyHu/Dropbox/PHP/Study/Runoob/RBase/Test13_welcome.php on line 9 Your email address is : Notice: Undefined index: email in /Users/JyHu/Dropbox/PHP/Study/Runoob/RBase/Test13_welcome.php on line 10</code>
It can be seen that the data can only be obtained by using file_get_contents, and there is no data in _REQUEST _POST.
But the test can be obtained by using get submission and using _GET.
According to some opinions on the Internet, the following two php.ini parameters are also set
<code>variables_order = "GPCS" enable_post_data_reading = True</code>
I just started to learn PHP and encountered difficulties when learning how to submit data through forms. Please give me some advice.
I learned it from the tutorials in these two places: RUNOOB, W3C
The problem is this, there is a form in the index.php page, use post to submit the data and then jump to the Test13_welcome.php page and enter This page gets the data, but it seems that it is possible to follow online tutorials, but it is really not possible here. The detailed description is as follows:
System: Mac OSX 10.11.5
IDE: PHPStorm 2016.1.2
PHP: 7.0.7
Browser: Safari and Chrome have been tried
The following is index.php
<code><html> <head> </head> <body> <form action="Test13_welcome.php" method="post" enctype="application/x-www-form-urlencoded"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit" name="submit"> </form> </body> </html></code>
The following is Test13_welcom.php
<code><html> <body> <?php var_dump($_REQUEST); var_dump($_POST); $a = file_get_contents('php://input', 'r'); echo $a.PHP_EOL; echo "<br>"; ?> Welcome : <?php echo $_POST["name"]; ?><br> Your email address is : <?php echo $_POST["email"]; ?> </body> </html></code>
After running, enter any data and the result will be displayed after the jump:
<code>array(0) { } array(0) { } name=234&email=2345&submit=%E6%8F%90%E4%BA%A4 Welcome : Notice: Undefined index: name in /Users/JyHu/Dropbox/PHP/Study/Runoob/RBase/Test13_welcome.php on line 9 Your email address is : Notice: Undefined index: email in /Users/JyHu/Dropbox/PHP/Study/Runoob/RBase/Test13_welcome.php on line 10</code>
It can be seen that the data can only be obtained by using file_get_contents, and there is no data in _REQUEST _POST.
But the test can be obtained by using get submission and using _GET.
According to some opinions on the Internet, the following two php.ini parameters are also set
<code>variables_order = "GPCS" enable_post_data_reading = True</code>
I have encountered this problem. The premise is that the built-in server of PhpStorm is used for debugging. Then look below. If not, just pretend I didn't say it.
First of all phpinfo();
How to download PhpStorm
XAMPP or a self-built PHP environment, and use Apache
The reason is that the built-in browser is simulated by FastCGI and does not have $_POST
The solution is to set PhpStorm to the Apache environment.
<code class="php"><?php var_dump($_REQUEST); var_dump($_POST); $a = file_get_contents('php://input', 'r'); echo $a.PHP_EOL; echo "<br>"; ?> <html> <body> Welcome : <?php echo $_POST["name"]; ?><br> Your email address is : <?php echo $_POST["email"]; ?> </body> </html></code>
The form action address is incorrect