Page 1 of 1

PHP form doesn't display data

Posted: Wed Sep 27, 2006 9:49 am
by analeah
Hi,

I have two files:

phpform.htm and process.php

which have the following code(which I got from an online tutorial):

phpform.htm:

Code: Select all

<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post">
<select name="item">
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input name="quantity" type="text" />
<input type="submit" />
</form>
</body></html>


process.php

Code: Select all

<html>
<body>
<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];
echo "You ordered ". $quantity . " " . $item . ".";
echo "Thank you for ordering from Tizag Art Supplies!";
?>
</body>
</html>



Every time enter data in the html form and hit submit, a blank page (no echo data) shows up.
I am using PHP Designer 2005 and WAMP with PHP. If I just run the php code on its own, it seems to work okay with the output, "You ordered .Thank you for ordering from Tizag Art Supplies! " so I'm slightly confused.

Any help would be greatly appreciated.

Thanks,
-Leia Chancellor

Posted: Wed Sep 27, 2006 10:08 am
by volka
You really should indent your code more carefully.
Try.

Code: Select all

<html>
	<head>
		<title>...</title>
	</head>
	<body>
		<h4>Tizag Art Supply Order Form</h4>
		<form action="process.php" method="post">
			<div>
				<select name="item">
					<option>Paint</option>
					<option>Brushes</option>
					<option>Erasers</option>
				</select>
				Quantity: <input name="quantity" type="text" />
				<input type="submit" />
			</div>
		</form>
	</body>
</html>

Code: Select all

<html>
	<head>
		<title>..</title>
	</head>
	<body>
		<h1>Tizag Art Supply Order confirmation</h1>
<?php
if ( !isset($_POST['quantity'], $_POST['item']) ) {
	echo 'item and quantity must be specified';
}
else {
	// lots of sanity checks, casts .... that justify the two new variables here....
	$quantity = $_POST['quantity'];
	$item = $_POST['item'];

	echo 'You ordered ', $quantity , " " , $item , ".
			<br />
			Thank you for ordering from Tizag Art Supplies!";
}
?>
	</body>
</html>

Thank you, But it still is not working

Posted: Wed Sep 27, 2006 10:12 am
by analeah
Hi,

Thank you very much for your suggestions. I tried using that code. Now at least I get someting on the page:
"Tizag Art Supply Order confirmation"
But none of the other data shows.

Any more ideas?

Thanks,
-Leia Chancellor

Posted: Wed Sep 27, 2006 10:22 am
by volka
Open the browser's source view (from the browser's menu bar: View->Sourcecode). Do you see the php tag and the php code there?

Posted: Wed Sep 27, 2006 10:27 am
by analeah
Hi,

Yes, I see the code for the process.php file there (and all of it inclouding the php tag and php code).

Thanks,
-Leia Chancellor

Posted: Wed Sep 27, 2006 10:37 am
by volka
Then the code hasn't been processed by php.
Either your webserver is not configured to let php handle php scripts. Or you didn't let the browser request the document from the webserver.

The red bordered input field is the location bar.
Image
What does it say in your location bar when you call the script?

Posted: Wed Sep 27, 2006 10:40 am
by analeah
Hi,

It says: "file:///C:/wamp/www/process.php"

Thank you,
-Leia Chancellor

Posted: Wed Sep 27, 2006 10:42 am
by volka
So the browser opens the file via local filesystem. There's no webserver and no php interpreter involved.
Start the webserver (wamp) and request the doc via http://localhost/process.php (or http://localhost/nameOfTheFileWithTheForm.html )
Not the browser interprets the php script. The webserver (and the installed the php module) does.

* Bows down to Vodka *

Posted: Wed Sep 27, 2006 10:45 am
by analeah
* Bows down to Volka *

Thank you very much! It works great now!

Posted: Wed Sep 27, 2006 4:40 pm
by panic!
Well spotted volka! I would have assumed they were running it from a web server!