PHP POST not working but GET works
Please make sure the "enable_post_data_reading" variable is set to "on" in php.ini. I have tried the same script on MAMP and it's working fine. So, It's your server settings issue.
PHP POST not working
If you're just refreshing the page, do:
action=''
instead of:
action="<?php echo $_SERVER['PHP_SELF'];?>"
Also, add this to line 2 to see what's being stored (if anything) in the $_POST array:
var_dump( $_POST );
Hmm... so it's empty on submit? Try adding this to the top of your php file:
if(empty($_SERVER['CONTENT_TYPE']))
{
$_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded";
}
Okay, now check your php.ini (normally requires sudo or root in /etc):
post_max_size = 8M
variables_order = "EGPCS"
Do you have those two rules set? If so, be careful of how much memory you're allocating. Anything over 2048MB could start to give you trouble, depending on your system specs.
NOTE: If you make changes to your php.ini file and PHP is running as an apache module, you'll need to restart apache. Something along the lines of:
sudo /etc/init.d/httpd restart
Post method not working in PHP
Updated to PHP 7.0 and it's working now!
Thanks everyone for their help!
php $_POST not working but $_GET is
I'm still not too sure what was causing it in the first place, but I have discovered that if I am making a request with a relative path then I have to omit the file extension. e.g. action="test-post"
instead of action="test-post.php"
.
File extensions seem to be fine for $_GET
and $_REQUEST
if I am sending it via get (method="get"
), but not for $_POST
or $_REQUEST
if I am sending it via post (method="post"
).
EDIT
This was something to do with the .htaccess
file. I don't know much about that file, so I don't know exactly which bit was causing this issue.
Php POST not receiving any data
Everything looks fine but the submit href link, which you should replace with a Submit input type:
<a href="welcome.php">Submit</a>
to:
<input type="submit">
Related Topics
Prevent Sent Emails Treated as Junk Mails Using PHP Mail Function
Adding Months to a Date in JavaScript
Pdo Prepared Statements With Wildcards
File_Get_Contents(): PHP_Network_Getaddresses: Getaddrinfo Failed: Name or Service Not Known
Resetting Array Pointer in Pdo Results
I Cannot Get My Login Form to Connect Interact Properly With MySQL Database
Insert - Number of Bind Variables Doesn't Match Number of Fields in Prepared Statement
Laravel Certificate Verification Errors When Sending Tls Email
Sanitizing Strings to Make Them Url and Filename Safe
Upgrading PHP in Xampp For Windows
How to Make Dot Match Newline Characters Using Regular Expressions
How to Use the PHP That Brew Installed
How to Successfully Rewrite Old MySQL-PHP Code With Deprecated MySQL_* Functions