PHP forms - 'get' working but 'post

2019-09-09 09:06发布

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

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>

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>";
?>

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

标签: php forms post get
4条回答
劳资没心,怎么记你
2楼-- · 2019-09-09 09:38

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.

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-09-09 09:39

i was using ckeditor on multiple textarea fields in the form, and getting the same error...

i tried everything.. like using get instead of post, played with mod securities and many more things whatever i could think off....

but finally i get it working when i removed ckeditor from the multiple fields... now its working perfectly fine...

may be some of the fields in your code are generating some intenal code that the browse/server treats as a injection the the sql queries, and therefore blocks the page directly.

find that code...

查看更多
Juvenile、少年°
4楼-- · 2019-09-09 09:42

There is another possibility that hasn't been mentioned yet, which is .htaccess

In some cases the .htaccess is set to either redirect or block a POST, which wouldn't catch and block or route a GET.

If you can navigate to the page (which you say you can), but a POST never gets there then something is blocking it and the only thing in the way is the web server platform that you're using.

You mentioned earlier that you were using a hosting provider, so ask them specifically what rules they have set up on POST requests (you'll probably have to wait a bit on hold to get somebody who can actually answer the question) or you can test this a bit from the command line with wget

wget --post-data 'name=test' http://server.com/tmp/register.php
查看更多
Lonely孤独者°
5楼-- · 2019-09-09 09:56

The error code says it's looking for the file at /tmp/register.php. Is that correct? Perhaps change the form action to /register.php?

Also, your PHP looks a bit off (lots of extra quotes), but I'm assuming you just copy/pasted from the php file and some reason deleted the surrounding HTML?

查看更多
登录 后发表回答