PHP POST不起作用 [英] PHP POST not working

查看:410
本文介绍了PHP POST不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php echo $ _POST ['ss'];?> 
< form action =<?php echo $ _SERVER ['PHP_SELF'];?>方法= POST >
< input name =sstype =text/>
< input type =submitname =submit>
< / form>

当点击提交时,此代码应打印文本框名称=ss中输入的内容。 >
但它没有打印。使用method =get而不是post,问题是什么。

做:

  action =''

而不是:

  action =<?php echo $ _SERVER ['PHP_SELF' ];?>中

另外,将其添加到第2行以查看$ _POST数组中存储的内容(如果有的话) :

  var_dump($ _POST); 

嗯...所以在提交时是空的?尝试将其添加到您的PHP文件的顶部:

  if(empty($ _ SERVER ['CONTENT_TYPE']))
{
$ _SERVER ['CONTENT_TYPE'] =application / x-www-form-urlencoded;
}

好的,现在检查你的php.ini(通常需要sudo或root in /等等):

  post_max_size = 8M 
variables_order =EGPCS

你有这两个规则吗?如果是这样,请注意您分配的内存量。任何超过2048MB的内容都可能会给您带来麻烦,具体取决于您的系统规格。



注意:如果您对php.ini文件进行更改并且PHP以apache模块,你需要重新启动Apache。

  sudo /etc/init.d/httpd restart 


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

解决方案

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

这篇关于PHP POST不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆