I am a newbie PHP Web Developer and currently reading the book 'PHP and MYSQL Web Development' by Luke Welling and Laura Thomson. Following what was written in the book, that is what I got:
<?php
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$address = $_POST['address'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$date = date('H:i, jS F Y');
?>
<html>
<head>
<title>Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
if($tireqty == 0 && $oilqty == 0 && $sparkqty == 0){
echo '<p>You did not order anything on the previous page!</p>';
exit;
}else{
echo '<p>Order Processed at '.$date.'</p>';
$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;
$totalamount = $totalamount * (1 + $taxrate);
echo '<p>'.'Total including tax: $'.number_format($totalamount,2).'<br /></p>';
echo '<p>Adress to ship to is '.$address.'<br />';
$outputString = $date."\t".$tireqty." tires \t".$oilqty." oil \t".$sparkqty." spark plugs \t".$totalamount."\t".$address."\n";
//opening files.
@ $fp = fopen("$DOCUMENT_ROOT/booktutorials/orders.txt", 'ab');
/////////////////////////////////HERE IS WHERE IT WOULD NOT WORK AS I WANT TO ////////////////////////////////////////////////////
if(!$fp){
echo "<p><strong> Your order could not be processed at this time. Please try again later.</strong></p>";
exit;
}
flock($fp, LOCK_EX);
fwrite($fp, $outputString, strlen($outputString));
flock($fp, LOCK_UN);
fclose($fp);
echo "<p>Order written.</p>";
echo '<hr />'. file_get_contents("$DOCUMENT_ROOT/booktutorials/orders.txt");
}
?>
</body>
</html>
All I get is 'Your order could not be processed at this time. Please try again later'. Even though I am pretty sure that the URL of the file is correct. Please help.
Thanks in advance.