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

Leave a Comment