elseif statement and operators not working?
Posted: Tue Aug 26, 2003 4:47 pm
Hi all, I have and order form that i made and in the form i have the php form script calling the processorder page e.g
<form action="processorder.php" method=post> now i think my form is ok here it is:
Now I have been working on the processorder.php page and i basically use some operators to work out the totals and tax ifelse statements and added the fopen() to open my orders.txt file.. now my fopen script works because when i put information into the order form and submit it i`m able to see Order written , but the problems is that no matter what amounts i put into the tire, oil or sparkplug field and into the address field its not echoed to the processorder page nothing comes tru. and my totals are at $0.00.. here is the script.. could someone try it and see what i`m referring to..
mod_edit: added
<form action="processorder.php" method=post> now i think my form is ok here it is:
Code: Select all
<html>
<head>
<title>Hazels Garage</title>
</head>
<body>
<h1>Hazels Garage</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=left><input type="text" name="tireqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Oil</td>
<td align=left><input type="text" name="oilqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align=left><input type="text" name="sparkqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Shipping Address</td>
<td align=center><input type="text" name="address" size=40 maxlength=40></td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value="Submit Order"></td>
</tr>
</table>
</form>
</body>
</html>Code: Select all
<html>
<head>
<title>Hazels Garage - Order Results</title>
</head>
<body>
<h1>Hazels Garage</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>";
define("TIREPRICE", 100);
define("OILPRICE", 10);
define("SPARKPRICE", 4);
$totalqty = $tireqty + $oilqty + $sparkqty;
$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;
$totalamount = number_format($totalamount, 2);
echo "<br>\n";
echo "Items ordered: ".$totalqty."<br>\n";
echo "Subtotal: $".$totalamount."<br>\n";
$taxrate = 0.10; // local sales tax is 10%
$totalamount = $totalamount * (1 + $taxrate);
$totalamount = number_format($totalamount, 2);
echo "Total including tax: $".$totalamount."<br>\n";
if( $totalqty == 0 )
{
echo "You did not order anything on the previous page!<br>";
}
else
{
if ( $tireqty>0 )
echo $tireqty." tires<br>";
if ( $oilqty>0 )
echo $oilqty." bottles of oil<br>";
if ( $sparkqty>0 )
echo $sparkqty." spark plugs<br>";
}
$total = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE;
$total=number_format($total, 2, ".", " ");
echo "<P>Total of order is ".$total."</p>";
echo "<P>Address to ship to is ".$address."<br>";
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
.$sparkqty." spark plugs\t\$".$total
."\t". $address."\n";
// open file for appending
@ $fp = fopen("C:\Program Files\Apache Group\Apache2\orders\orders.txt", "a");
flock($fp, 2);
if (!$fp)
{
echo "<p><strong> Your order could not be processed at this time. "
."Please try again later.</strong></p></body></html>";
exit;
}
fwrite($fp, $outputstring);
flock($fp, 3);
fclose($fp);
echo "<p>Order written.</p>";
?>
</body>
</html>Code: Select all
amdCode: Select all
tags[/size]
this is what i get on the page..
<----
Hazels Garage
Order Results
Order processed.17:46, 26th August
Your order is as follows:
tires
bottles of oil
spark plugs
Items ordered: 0
Subtotal: $0.00
Total including tax: $0.00
You did not order anything on the previous page!
Total of order is 0.00
Address to ship to is
Order written.
--->