Page 1 of 1

help with a very basic script

Posted: Mon Sep 02, 2002 1:14 pm
by smoky989
ok I has some programming experience, I just bought a PHP/mySQL book and in the very first example I'm gettig a problem. It could be a setting because all the examples in the book are on cd and I get the same error

Notice: Undefined variable: tireqty in c:\program files\apache group\apache\htdocs\chapter1\processorder.php on line 14
tires

I get this for my three variables past from an html form. Heres the code for the HTML form.

<html>
<head>
<title>Dave's Auto Parts</title>
</head>
<body>
<h1>Dave's Auto Parts</h1>
<h2>Order Form</h2>
<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>Tires</td>
<td align="center"><input type="text" name="tireqty" 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>


Here is the code for the PHP script

<html>
<head>
<title>Dave's Auto Parts - Order Results</title>
</head>
<body>
<h1>Dave's Auto Parts</h1>
<h2>Order Results</h2>
<?
echo "<p>Order processed.";
echo date("H:i, jS F");
echo "<br>";
echo "<p>Your order is as follows:";
echo "<br>";
echo $tireqty. " tires<br>";
echo $oilqty. " bottles of oil<br>";
echo $sparkqty. " spark plugs <br>";
?>
</body>
</html>

I'm using Apache and Windows 2000 any suggestions???

Posted: Mon Sep 02, 2002 1:20 pm
by fatalcure

Posted: Mon Sep 02, 2002 3:58 pm
by ssand
Sounds like you have the PHP and MySQL Web Development book. I also purchased that book and noticed that they have several typos in the first couple chapters.
Also, make sure your variable names match the scripts off the CD as I think the book and CD didn't always match.

Posted: Tue Sep 03, 2002 1:51 am
by twigletmac
From what you should have learned about in the sticky that fatalcure pointed you towards. Instead of this:

Code: Select all

echo $tireqty. " tires&lt;br&gt;"; 
echo $oilqty. " bottles of oil&lt;br&gt;"; 
echo $sparkqty. " spark plugs &lt;br&gt;";
try this:

Code: Select all

echo $_POST&#1111;'tireqty'].'tires&lt;br&gt;'; 
echo $_POST&#1111;'oilqty'].'bottles of oil&lt;br&gt;'; 
echo $_POST&#1111;'sparkqty'].'spark plugs&lt;br&gt;';
Mac

Posted: Tue Sep 03, 2002 4:08 am
by pat001
twigletmac has given you the best and recommended way to sort out your problem, but there's an easier way which should make all the code in the (excellent) book work - go into your php.ini file and change register_globals to On.
This has been set to Off by default in new versions of PHP, as it is more secure to access your variables via the $_POST, $_GET, $_SESSION etc. arrays, or via the $HTTP_POST_VARS etc, etc, ones.
But if you can, better to get into good habits from the start, when you don't have to go back and recode all your sites!