PHP POST not working

34,036

Solution 1

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

Solution 2

It may be due to rewrite rules in the .htaccess file.Add this condition to your .htaccess file

RewriteCond %{REQUEST_METHOD} !POST [NC]

OR add this line

 RewriteRule ^welcome_post.php - [PT]

Solution 3

I broken my post method once that I set post_max_size the same with upload_max_filesize.

I think that post_max_size must less than upload_max_filesize.
Tested with PHP 5.3.3 in RHEL 6.0

Solution 4

Finally ...Got it.... Firstly I have an Article folder in my htdocs file with welcome.php as the php file in focus and a main HTML file , whose contents we will be discussing about. Here's what worked for me.. Turns out the problem was not XAMPP or any of its related files.. The problem was this :

<form action="welcome.php" method="post">

With this code whenever I pressed the submit button, the url redirects to here file:///C:/xampp/htdocs/Article/welcome.php, Which is not what it needs to be..It has to be a localhost link ..So I changed the value of action attribute to localhost form and now it looks like this

<form action="https://localhost/Article/welcome.php" method="post">

That did the trick..Now the submit button redirects to https://localhost/Article/welcome.php , this link..Which is exactly what is needed.. Remember the browser may ask you for some permission issues ..Just accept them it will run fine... Best of luck.. P.S : This one is for Windows..Hope it will work also in Linux and Mac.

Share:
34,036
Wasim A.
Author by

Wasim A.

[email protected] | Skype:wasimxe | Whatsapp: +923455407008

Updated on November 23, 2020

Comments

  • Wasim A.
    Wasim A. over 3 years
    <?php echo $_POST['ss'];?>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    <input name="ss" type="text" />
    <input type="submit" name="submit">
    </form>
    

    This code should print whatever is enter in text box name="ss" when click submit.
    But its not printing. Working with method="get" but not with post, What's the problem.