So I have an assignment where I have to create a .html and .php file. My .html works perfectly, but my .php doesn't.
<html>
<head>
<title>Bob's Auto Parts</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Form</h2>
<form action="processorder2.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>
Thats my .html and it works perfect, but its my .php that doesnt.
<?php
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$address = $_POST['address'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts and Winery - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts and Winery</h1>
<h2>Order Results</h2>
<?php
$date = date("F - d - Y");
echo '<p>Order processed at ';
echo $date;
echo '</p>';
echo '<p>Your order is as follows: </p>';
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo 'Items ordered: '.$totalqty.'<br />';
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 />';
}
$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);
$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;
-1-
G:\public_html\processorder2.php Friday, October 10, 2008 1:43 PM
$totalamount=number_format($totalamount, 2, '.', ' ');
echo '<p>Total of order is '.$totalamount.'</p>';
echo '<p>Address to ship to is '.$address.'</p>';
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
.$sparkqty." spark plugs\t\$".$totalamount
."\t". $address."\n";
// open file for appending
$filename = "orders.txt";
echo '<p>filename is '.$filename.'</p>';
@ $fp = fopen($filename, 'ab');
echo '<p>open to lock </p>';
flock($fp, LOCK_EX);
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, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);
echo '<p>Order written.</p>';
?>
</body>
</html>
It is supposed to end up looking like this when you get to the .php part after you try the site out:
Bob's Auto Parts and Winery
Order Results
Order processed at February - 13 - 2009
Your order is as follows:
Items ordered: 3
1 tires
1 bottles of oil
1 spark plugs
Total of order is 114.00
Address to ship to is 1
filename is orders.txt
open to lock
Your order could not be processed at this time. Please try again later.
Can anyone help? Thanks!