PHP form doesn't display data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
analeah
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 9:42 am

PHP form doesn't display data

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
analeah
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 9:42 am

Thank you, But it still is not working

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
analeah
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 9:42 am

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
analeah
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 9:42 am

Post by analeah »

Hi,

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

Thank you,
-Leia Chancellor
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Last edited by volka on Wed Sep 27, 2006 10:45 am, edited 1 time in total.
analeah
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 9:42 am

* Bows down to Vodka *

Post by analeah »

* Bows down to Volka *

Thank you very much! It works great now!
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Post by panic! »

Well spotted volka! I would have assumed they were running it from a web server!
Post Reply