Click to See Complete Forum and Search --> : Can someone test this for me


moondance
05-30-2003, 01:31 PM
i've just started to learn php. I installed apache, php and mySQL so they work offline.

I've been teaching myself from this book. Problem is, i've copied a tutorial from the book, word for word, and its not giving the same response thats in the book.

I know apache, and mysql work fine. PHP works also, as the date and time are displayed dynamically, yet the other values aren't.

Can someone have a try on their computer and tell me if i've configured php wrong or if theres an error in my code.

ta ;)

Heres the html page:
<html>
<head>
</head>
<body>
<form action = "processorder.php" method=post>
<table border =0>
<tr bgcolor =#cccccc>
<td width =150>Item</td>
<td width =15>Quantity</td>
</tr>
<tr>
<td>Tyres</td>
<td align =center><input type="text" name="TyreQty" size =3 maxlength=3></td>
</tr>
<tr>
<td>Oil</td>
<td align =center><input type ="text" name="OilQty" size =3 maxlength =3></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align =center><input type ="text" name="SparkQty" size =3 maxlength=3></td>
</tr>
<tr>
<td colspan =2 align =center><input type =submit value ="Submit Order"></td>
</tr>
</table>
</form>
</body>
</html>


and heres the php file:

<html>
<head>
<title> Your Order</title>
</head>
<body>
<h1>Maxwells Motor Parts</h1>
<h2>Your Order Inventory:</h2>
<?
echo "<p>Order processed at " ;
echo date("H:i, jS F");
echo "<br>";
echo "Your order is as follows" ;
echo "<br>";
echo $TyreQty. " tyres<br>";
echo $OilQty. " cans of oil<br>";
echo $SparkQty. " spark plugs<br>";
</body>
</html>

Nevermore
05-30-2003, 02:04 PM
K, I ran it, and first I got

Parse error: parse error, unexpected '<' in C:\Documents and Settings\Jacob Ward\My Documents\Web Pages\Help\processorder.php on line 17.
That was because the PHP block wasn't ended before the HTML block started. So I fixed that,
Next, it said the variables were undefined. This was because my server at least doesn't like using post and get variables without defining them. So I fixed that.

Then it said:

Maxwells Motor Parts
Your Order Inventory:

Order processed at 20:03, 30th April
Your order is as follows
1 tyres
2 cans of oil
3 spark plugs

here's the code. I don't know how many of the errors I got that you got, but you shouldn't get them with this.

<html>
<head>
<title> Your Order</title>
</head>
<body>
<h1>Maxwells Motor Parts</h1>
<h2>Your Order Inventory:</h2>
<?
echo "<p>Order processed at " ;
echo date("H:i, jS F");
echo "<br>";
echo "Your order is as follows" ;
echo "<br>";
echo $_POST['TyreQty'] . " tyres<br>";
echo $_POST['OilQty'] . " cans of oil<br>";
echo $_POST['SparkQty'] . " spark plugs<br>";
?>
</body>
</html>

pyro
05-30-2003, 03:50 PM
Originally posted by cijori
This was because my server at least doesn't like using post and get variables without defining them.In PHP 4.2.0, global variables (like the script moondance used) are disabled as a default. You are MUCH better of not using global variables, like cijori did in his code.

moondance
05-30-2003, 06:23 PM
how do i not use global variables?

does that mean i have to declare each variable at the top of the php script in a similar way to visual basic?

so hang on...not use global variables....thats the $post isn't it? why is it bad to use them, and in that case, how can i get round the problem?

*sits there confoosed*
:confused:

DaiWelsh
05-31-2003, 01:52 AM
This thread explains about as clearly as possible

http://forums.devnetwork.net/viewtopic.php?t=511

HTH,

Dai

pyro
06-01-2003, 06:20 PM
Did DiaWelsh's link clear it up? If not, let me know and I will explain...