Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post Method on Forms not working

Status
Not open for further replies.

micknh

Programmer
Apr 19, 2005
13
US
I am unable to display PHP pages generated by a submission of a form using a POST method. To illustrate this, I created a very simple form called TestForm.php .

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Form</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr><td>Name</td><td><input type="text" name="name0"/></td></tr>
<tr><td>Age</td><td><input type="text" name="age0"/></td></tr>
</table>
<input type="submit" name="SubmitMe" value="Submitted" />
</form>
</body>
</html>
I first set the method for the form to GET and the page loaded again after the submit.
When I changed the method back to POST, I received a Page Not Found error page.
I created another page testform3.php to display the Form Values after submit. I changed the action on the form to testform3.php.

I am frustrated.
Windows 2k Server SP4
IIS 5
PHP 5.04
MySQL 4.1.11

Any and all help would be appreciated.
 
when you submit you have to send it to a page...that is probably why you are getting that error. change this part
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
to
<form action="testform3.php" method="post">

David Kuhn
------------------
 
Thanks for the reply.

I did do that. I was just showing the first simple form I was using but I did change the action to the testform3.php page when I was sending the results to another page.

It still isn't working either way but if I changed the method to get it will work fine. We can't use the get method unfortunately.

Thanks,

Michael
 
My test for the absence of the Post variables was simply that the code worked when I sent it by Get instead of Post.

I did try putting in a print_r of the post variables at the top of the result page but it didn't print anything and just displayed the Page Not Found Error Page
 
If you're getting a "Page Not Found" error, then there is something wrong with your <form> tag.

Do a show source for each script, before you submit the form, and compare the generated HTML.

I would also check your server log files to see if there is a hint of what's going on in them.

Ken
 
micknh:

The simplest possible test case I can think of consists of:

test.html
Code:
<html><body>
<form method="post" action="test.php">
<input type="submit" name="submit_button">
</form>
</body></html>

test.php
Code:
<?php
print '<html><body><pre>';
print_r ($_POST);
print '</pre></body></html>';
?>

How does this test perform?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214,

The test.htm page displayed correctly. When I submitted the form I got a page not found error page. The test.php was located in the same directory as the test.htm page.

Any other suggestions,

Michael
 
If you just put the URL for test.php into your browser, what happens?
 
Hi,

It would show the page.

We finally have the answer. The problem was a program called URL Scan which is distributed by Microsoft to answer some of the security problems of the older versions of IIS.

Someone at PHPbuilder.net sent me this:

Running Win2K AS + IIS5.0 + PHP 4.3.1, I ran into a nasty problem that I mistakenly thought had to do with something in the php.ini configuration. When I would try to submit a form using the HTTP method GET it would work, but I would get a "404 Page Not Found" error using the POST method.

All my permissions were set correctly, the php.ini was configured correctly. It had to do with URLScan being installed on IIS (see below)

Page 404 File Not Found Error When Using POST method in PHP (and Perl, and otherwise)
-------------------------------------------

This is related to the Microsoft URLScan utility. If you have this problem, the IIS administrator has probably run the IIS Lockdown tool as well as configured URLScan to reject this type of HTTP method when sent in a URL. These tools are meant to enhance web server security.

URLScan configuration files can be found in the \WINNT\system32\inetsrv\urlscan folder on the web server. Specifically, the file to modify is urlscan.ini.

The changes to make are as follows:
1. Make sure UseAllowVerbs=1 under [options]
2. Under the [AllowVerbs] section, list your allowed HTTP methods to include:
GET
POST

For more information on the IIS Lockdown tool and URLScan, visit
We uninstalled that program (we will reinstall after more research) and voila php pages appear out of the ether.

Thanks to all who helped.
 
micknh this is a very good information. This issue is not easy to resolve. Many thanks for posting the solution!!

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top