I want to print out the data from $_POST, but for some reason the PHP side isn't receiving the data when I do POST.
Here's the super simple code in a file called test.php
<?php
echo "<b>GET </b>";
print_r($_GET);
echo "<br><b>POST </b>";
print_r($_POST);
?>
<html>
<body>
<form action="test.php" method="post">
<input type="text" name="name"><br>
<input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
When I visit http://localhost:63342/pastr/test.php and fill in a name and email and click submit the information does get posted. I checked from Chrome's network tab and saw that the data is getting posted like name=this+should+get+posted+as+name&email=this+should+get+posted+as+email.
Here's a screenshot of the full headers in case the issue might be hidden there: https://i.sstatic.net/OEtga.png
Everything seems to be working except the webpage displays this:
GET Array ( )
POST Array ( )
The POST array is somehow empty? What have I done wrong?
Note, this works fine if I change the method to GET, when I change to get I see this:
GET Array ( [name] => this should be name [email] => this should be email )
POST Array ( )
My question is: What am I doing wrong here in trying to print out the POST-ed data and how can I fix it so that I can print out the received name and email?
Note: trying echo $_POST['name'] and echo $_POST['email'] both result in a very similar errors: Notice: Undefined index: name in C:\Users\Admin\Desktop\2\g\pastr\test.php on line 8
Notice: Undefined index: email in C:\Users\Admin\Desktop\2\g\pastr\test.php on line 9
Use Apache from WAMP (or any other proper web server) to serve your web requests. Right now you are using PhpStorm's own built-in simple web server which ATM has issues with handling POST requests.
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With