PHP $ _POST不工作? [英] PHP $_POST not working?
问题描述
我有最简单的形式,我想要做的就是回应文本框中写的任何内容。
$ b HTML:
< form action =method =post>
< input type =textname =firstname>
< input type =submitname =submitvalue =Submit>
< / form>
PHP:
if(isset($ _ POST ['submit'])){
您也可以替换
$ test = $ _POST ['firstname'];
echo $ test;
$ b $ p
$ b问题是它不能在我的服务器上工作(它在另一台服务器上工作) 。有没有人有一个想法可能是错的?在服务器上还有其他的表单,并且工作正常。
解决方案您可以执行一些操作:
- 请确保表单上的action属性导致正确的目的地。
link 也可能有帮助。
- 尝试使用$ _REQUEST []而不是$ _POST,看看是否有任何改变。
[可选]尝试包括'name'和'id'属性,例如
< input type =textname =firstnameid =firstname>
在Linux环境中,请检查您是否拥有对该文件的读/写权限。
编辑:
如果(isset($ _ POST ['submit'])){
>
with this:
if($ _ SERVER ['REQUEST_METHOD'] ==POST){
。这总是检查表单是否已被提交的最佳方式。I have the simplest form possible and all I want to do is echo whatever is written in text box.
HTML:
<form action="" method="post"> <input type="text" name="firstname"> <input type="submit" name="submit" value="Submit"> </form>
PHP:
if(isset($_POST['submit'])){ $test = $_POST['firstname']; echo $test; }
The problem is it's not working on my server (it works on another server). Does anyone has an idea what could be wrong? There are other forms on the server and are working fine.
解决方案A few thing you could do:
- Make sure that the "action" attribute on your form leads to the correct destination.
- Try using $_REQUEST[] instead of $_POST, see if there is any change.
[Optional] Try including both a 'name' and an 'id' attribute e.g.
<input type="text" name="firstname" id="firstname">
If you are in a Linux environment, check that you have both Read/Write permissions to the file.
In addition, this link might also help.
EDIT:
You could also substitute
if(isset($_POST['submit'])){
with this:if($_SERVER['REQUEST_METHOD'] == "POST"){
. This is always the best way of checking whether or not a form has been submitted这篇关于PHP $ _POST不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!