Hello
I'm having a problem with my php script. It's about writing lines to a text file. The script runs normally without any errors, but it leaves the text file empty, no matter how many times I run it. I'm using WAMP server.
Here's the code:
<?php //kratke varijable
$tireqty=$_POST['tireqty'];
$oilqty=$_POST['oilqty'];
$sparkqty=$_POST['sparkqty'];
$adress=$_POST['adress'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$date = date('H:i, jS F Y');
?>
<html>
<head>
<meta charset="utf-8">
<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 ".date ('H:i, jS F Y')."</p>";
echo "<p>Your order is as follows: </p>";
$totalqty=0;
$totalqty=$tireqty+$sparkqty+$oilqty;
echo "Item ordered: ".$totalqty."<br />";
if ($totalqty == 0) {
echo "You didn't order anyting from previous page!<br />";
} else {
if($tireqty>0)
echo $tireqty." tires<br />";
if($oilqty>0)
echo $oilqty." oil<br />";
if($sparkqty>0)
echo $sparkqty." sparks<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.20; // local sales tax is 20%
$totalamount = $totalamount * (1 + $taxrate);
echo 'Total including tax: $'.number_format($totalamount,2).'<br />';
echo '<p>Adress to ship to is '.$adress.'</p>';
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
.$sparkqty." spark plugs\t\$".$totalamount
."\t". $adress."\n";
//open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab');
if(!$fp) {
echo "<p><strong> Your order could not be processed at this time.<br>
Please try again later. </strong></p></body></html>";
exit;
}
flock($fp, LOCK_EX);
echo fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);
echo "<p>Order written.</p>";
?>
</body>
</html>
Thanks in advance for any help.