HTML forms not working with PHP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

HTML forms not working with PHP

Postby peamik » 24. May 2008 22:28

Hi. I am a newbie on this forum, and also new to XAMPP/HTML/PHP too, tho learning fast (I hope!). I am stuck trying to get HTML forms working under XAMPP with WinXP SP2.

HTML & PHP work fine independently. PHPINFO() returns appropriate results & all the install tests of XAMPP checked out fine too.

However, in creating an HTML form with an associated PHP script to process the input, I find that all I get is internet explorer returning a page showing the php script itself.

Here is script testPHPform.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing of forms</title>
</head>

<body>
<form action="testPHPform.php" method="post">
<select name="item">
<option>A4 paper</option>
<option>A5 paper</option>
<option>A6 paper</option>
</select>
Quantity: <input name="quantity" type="text" />
<input type="submit" />
</form>

</body>
</html>

and here is script testPHPform.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test PHP handling of form data</title>
</head>

<body>
<?php
$quantity=$_POST['quantity'];
$item=$_POST['item'];

echo "you requested ".$quantity." reams of ".$item.".<br />";

?>
</body>
</html>

The form displays fine. However, when I click the Submit button, instead of getting just the expected text "you requested 10 reams of A4 paper", I actually get the entire php script as shown above listed, and Internet explorer shows the address as C:\xampp\htdocs\testPHPform.php

If I explicitly invoke the php script in ie using url http://localhost/testPHPform.php, it displays the text ok, which suggests that XAMPP is running php fine, and that there is nothing essentially wrong with the php script itself.

But why do I not get the text when it is invoked via the HTML form?

I did wonder if there was some incorrect setting in the php.ini file, but so far I have been unable to identify anything that might relate to this problem.

The other odd thing is that I have some sample scripts from Larry Ullman's "PHP and MySQL for dynamic web sites" (first edition) which I downloaded from www.DMCinsights.com/phpmysql. The scripts from chapter 2 for HTML form and php script to process the input operate differently. In this instance, when submit is selected, IE again provides an address of C:\xampp\htdocs\handle_form.php, but nothing whatsoever is displayed.

I've even hand-coded up the exact same scripts, but then I get the php script content displayed, as described in the first example above, which leads me to think that somehow there must be some difference between the scripts themselves (perhaps in the properties of the .php file itself??), leading to a difference in the way apache handles them.

This is all very mystifying. If anyone can make any suggestion as to where the problem lies, or how I can configure XAMPP/PHP to give me more information on what it thinks the problem is, I would be most grateful.
Mike
peamik
 
Posts: 2
Joined: 24. May 2008 21:47

Postby Wiedmann » 24. May 2008 23:55

Ho0w did you open the file "testPHPform.html" exactly?
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby peamik » 25. May 2008 06:39

Hi Wiedmann

Thanks for your quick response.

To create the file I used notepad. To actually execute it I used windows explorer to navigate to the folder and then simply double-clicked it from the C:\xampp\htdocs\testPHPform.html folder.

You've set me thinking now. I have just tried executing it directly from IE using http://localhost/testPHPform.html, and of course it now works correctly!

Oh boy, I should have thought of that! Many many thanks. I won't forget that lesson in a hurry

Kind regards
Mike
peamik
 
Posts: 2
Joined: 24. May 2008 21:47


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 52 guests