help with a very basic script

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
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

help with a very basic script

Post 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???
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

ssand
Forum Commoner
Posts: 72
Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
pat001
Forum Newbie
Posts: 3
Joined: Tue Sep 03, 2002 4:08 am

Post 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!
Post Reply