PHP POST not working

2019-01-04 03:17发布

<?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.

9条回答
孤傲高冷的网名
2楼-- · 2019-01-04 03:56

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]
查看更多
Bombasti
3楼-- · 2019-01-04 03:58

First make sure that your web service (GET/POST etc) is acting as desired using the Chrome Advanced Rest Client. Then you should check your PHP part.

查看更多
地球回转人心会变
4楼-- · 2019-01-04 03:59

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
查看更多
迷人小祖宗
5楼-- · 2019-01-04 03:59

I solved mine with including following into header.

Content-Type: application/x-www-form-urlencoded

Just use this in the header while making a request and my problem was solved.

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-01-04 04:04

My friend ran into this problem today. The answer was pretty simple - basically, you have to capitalize the POST part of method="POST"

The final result should look like

<?php echo $_POST['ss'];?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input name="ss" type="text" />
<input type="submit" name="submit">
</form>
查看更多
唯我独甜
7楼-- · 2019-01-04 04:11

use this instead;

$variable_name = $_REQUEST["ss"];
echo $variable_name;
查看更多
登录 后发表回答