PHP表单 - 'get'工作,但'post'不行 [英] PHP forms - 'get' working but 'post' not
问题描述
我有一个简单的注册表单。我一直在寻找几个小时,并尝试了所有的东西 - 基本上我已经把它剥下来发布/获取。当我将方法设置为get(在表单和脚本页面上)时,它工作正常,当我将其设置为发布时,出现此错误:
I have a simple registration form. I've been searching for hours and tried everything - basically I've stripped it down to post/get. When I set the method to get (on both the form and script page) it works fine, when I set it to post, I get this error:
不可接受
Not Acceptable
在此服务器上找不到所需资源/tmp/register.php的适当表示。
此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。
An appropriate representation of the requested resource /tmp/register.php could not be found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
这是我的表单页上的代码:
Here is my code on the form page:
<form id="registration" onsubmit="return validateRegistration();" action="register.php" method="post">
Name: <input type="text" id="name" name="name" placeholder="Required">
<br>
Email: <input type="email" id="email" name="email" placeholder="Required">
<br>
Confirm: <input type="email" id="confirm_email" autocomplete="off" placeholder="Required">
<br>
Password: <input type="password" id="password" name="password" placeholder="Required">
<br>
Confirm: <input type="password" id="confirm_password" autocomplete="off" placeholder="Required">
<br>
City: <input type="text" id="city" name="city" placeholder="Optional">
<br>
Country: <input type="text" id="country" name="country" placeholder="Optional">
<br>
<br>
<hr>
<a href="#">Terms and Conditions</a>
<br>
<input type="submit" value="Accept and Complete Registration">
</form>
在我的脚本页面(register.php)中,我有:
And on my script page (register.php), I have:
<?php
echo "Name: " . $_POST["name"] . "<br>";
echo "Email: " . $_POST["email"] . "<br>";
echo "Password: " . $_POST["password"] . "<br>";
echo "Location: " . $_POST["city"] . ", " . $_POST["country"] . "<br>";
?>
如果我只是转到 register.php
它只是显示邮件的空白处,但是如果我提交表单,它会给出不可接受的406错误。
If I just go to register.php
it just shows blanks where the Posts are, but if I submit the form it gives the Not Acceptable 406 error.
有人可以帮我解决吗?我完全惊呆了。谢谢
Can someone please help me with this? I'm totally boggled. Thanks
推荐答案
我不知道你是否曾经找到过解决问题的答案。我也遇到了这个问题,POST会返回绝对没有数据,但GET流没有错误。
I don't know if you ever found an answer to your problem. I too was running into this issue, where POST would return absolutely no data but GET flowed without error.
关于我的问题的奇怪部分是,我只是把它我的网站之一。所有的网站都在同一台服务器上。
The odd part about my issue was that I was ONLY having it on one of my sites. All sites are on the same server.
经过大约3个小时将我的脸撞击到键盘后,我意识到了这一点。一个没有工作的网站,我已经设置了URL编码,总是删除www。我的解决方案是强制URL始终添加www,问题就没有了。
After about 3 hours of ceremoniously bashing my face into the keyboard, I had a realization. The one site that did not work I had set the URL encoding to always remove "www". My solution was to enforce the URL to always add "www" and the issue was gone.
这篇关于PHP表单 - 'get'工作,但'post'不行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!