PHP $_POST 不起作用
我正在使用 PHP 开发一个 Web 应用程序。 一些我以前从未见过的错误正在发生。 $_GET
工作正常,但 $_POST
无法正常工作。想象一下下面的表单:
<form action="process.php" method="post">
<input type="text" name="title" />
<input type="submit" value="send" />
</form>
如您所见,我使用 post 作为表单的方法属性。在这种情况下,下面的代码将返回错误:
<?php
$sentData = $_POST['title'];
echo($sentData);
?>
错误消息:
PHP Notice: Undefined index: title in ...
但是如果我在 php 脚本中使用 $_GET
并在 html 表单代码中使用 get
,则一切都会正常工作,而无需任何错误。
还有更奇怪的事情。
- 当我使用 POST 时,只有一种形式不返回错误,其他形式返回错误。
- 当我在本地运行此应用程序(使用 Xampp - Apache 2.2)时,一切正常,没有任何错误,但每当我在远程服务器(IIS 7)上运行该应用程序时,我都会遇到这些错误和问题。
I'm working a web application with PHP.
Something wrong is happening that I have never seen before. $_GET
is working well, but $_POST
does not work exactly. Imagine the form below:
<form action="process.php" method="post">
<input type="text" name="title" />
<input type="submit" value="send" />
</form>
As you see, I've used post for method attribute of the form. In this case, the code below will return error:
<?php
$sentData = $_POST['title'];
echo($sentData);
?>
Error message:
PHP Notice: Undefined index: title in ...
But If I had used $_GET
in php scripts and get
in the html form codes, everything would work without any error.
There are something more strange.
- There are just one form that returns no error while I'm using POST, other forms return error.
- When I run this application locally (with Xampp - Apache 2.2) everything works fine without any error, but whenever I run the application an the remote server (IIS 7), I get these errors and problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以我会用几种不同的方式来解决这个问题:
如果您正在使用框架或进行路由的东西,这可能是值得研究的事情。
我希望这会有所帮助,并且有更多错误报告设置[此处] http:// php.net/manual/en/function.error-reporting.php
so i would approach this in a couple of different ways:
if you're using a framework or something that does routing, this could be something to look into.
i hope this helps and there are more settings for error reporting [here] http://php.net/manual/en/function.error-reporting.php
您的输入元素需要名称和值属性。
Your input element needs both a name and value property.
最后我更改了我的文件所在的服务器。我在另一台服务器(相同的操作系统)上尝试了它们,一切正常。
我不明白原因是什么......这是我第一次遇到这个未知错误。
不过,还是谢谢大家的建议和意见。
Finally I changed the server that my files were located on it. I tried them on another server (same OS), and everything worked fine.
I could not get what was the reason... This was the first time that I was getting this unknown error.
However, thank you all for your suggestions and comments.