Hi,
I've just bought the book PHP and MYSQL Web Development and have started to work through the examples. I'm running Linux Mint 14 with an Apache server. I installed PHP and MYSQL using Apache Friends. The server is started and simple PHP programs are working correctly. Code is saved to a 'tutorials' folder in apache htdocs using eclipse with the php plug-in.
I started a new php project in eclipse and added two files to the project. the first is an html file which I have called index.html. This is the code:
Code:
<html>
<head><title>Bob's Auto Parts</title></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>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>How did you find Bob's?</td>
<td><select name="find">
<option value = "a">I'm a regular customer</option>
<option value = "b">TV advertising</option>
<option value = "c">Phone directory</option>
<option value = "d">Word of mouth</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Order" /></td>
</tr>
</table>
</form>
</body>
</html>
Variable such as tireqty and oilqty are defined. The second file named processorder (defined as a form action in the html file) contains this code.
Code:
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo '<p>Order processed at ';
echo date('H:i, jS F');
echo '</p>';
echo '<p>Your order is as follows: </p>';
echo $tireqty.' tires<br />';
echo $oilqty.' bottles of oil<br />';
echo $sparkqty.' spark plugs<br />';
$totalqty = 0;
$totalamount = 0.00;
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo 'Items ordered: '.$totalqty.'<br />';
$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);
$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;
echo 'Subtotal: $'.number_format($totalamount,2).'<br />';
$taxrate = 0.10; // local sales tax is 10%
$totalamount = $totalamount * (1 + $taxrate);
echo 'Total including tax: $'.number_format($totalamount,2).'<br />';
?>
</body>
</html>
These examples are copied direclty from the book.
Line 5 in the html code
is generating a warning in eclipse and i get the following error when i run localhost/tutorials. Here is the error generated:
Code:
Bob's Auto Parts
Order Results
Order processed at 22:38, 18th January
Your order is as follows:
Notice: Undefined variable: tireqty in /opt/lampp/htdocs/tutorials/processorder.php on line 13
tires
Notice: Undefined variable: oilqty in /opt/lampp/htdocs/tutorials/processorder.php on line 14
bottles of oil
Notice: Undefined variable: sparkqty in /opt/lampp/htdocs/tutorials/processorder.php on line 15
spark plugs
Notice: Undefined variable: tireqty in /opt/lampp/htdocs/tutorials/processorder.php on line 21
Notice: Undefined variable: oilqty in /opt/lampp/htdocs/tutorials/processorder.php on line 21
Notice: Undefined variable: sparkqty in /opt/lampp/htdocs/tutorials/processorder.php on line 21
Items ordered: 0
Notice: Undefined variable: tireqty in /opt/lampp/htdocs/tutorials/processorder.php on line 31
Notice: Undefined variable: oilqty in /opt/lampp/htdocs/tutorials/processorder.php on line 32
Notice: Undefined variable: sparkqty in /opt/lampp/htdocs/tutorials/processorder.php on line 32
Subtotal: $0.00
Total including tax: $0.00
Can anyone help with these errors. Code is exactly as listed in the book.
Thanks,
Tim