Hello,
I'm new to PHP so please bear with me. Everything seems to work as I wanted it up until "$outputstring" and below (I posted the whole script below). It does not seem to write anything to orders.txt. I verified that document_root = /var/www/html. I am also not receiving any error message. I have verified that /var/www/html/orders.txt is rwx for all users. Please help. thank you.
<?php
// create short variable names
$shirt_qty = $POST['shirt_qty'];
$pants_qty = $POST['pants_qty'];
$skirt_qty = $POST['skirt_qty'];
$shorts_qty = $POST['shorts_qty'];
$acc_qty = $POST['acc_qty'];
$address = $POST['address'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$date = date('e H:i, F jS Y'); // changed date format
?>
<html>
<head>
<title>Bob's Clothing Store - Order Results</title>
</head>
<body>
<h1>Bob's Clothing Store</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ".$date."</p>";
echo "<p>Your order is as follows: </p>";
$totalqty = 0;
$totalqty = $shirt_qty + $pants_qty + $skirt_qty + $shorts_qty + $acc_qty;
echo "Items ordered: ".$totalqty."<br />";
if ($totalqty == 0) {
echo "You did not order anything on the previous page!<br />";
} else {
if ($shirt_qty > 0) {
echo $shirt_qty." shirts<br />";
}
if ($pants_qty > 0) {
echo $pants_qty." pants<br />";
}
if ($skirt_qty > 0) {
echo $skirt_qty." skirts<br />";
}
if ($shorts_qty > 0) {
echo $shorts_qty." shorts<br />";
}
if ($acc_qty > 0) {
echo $acc_qty." accessories<br />";
}
}
$totalamount = 0.00;
define('SHIRTPRICE', 50);
define('PANTSPRICE', 20);
define('SKIRTPRICE', 40);
define('SHORTSPRICE', 30);
define('ACCPRICE', 10);
$totalamount = $shirt_qty * SHIRTPRICE
+ $pants_qty * PANTSPRICE
+ $skirt_qty * SKIRTPRICE
+ $shorts_qty * SHORTSPRICE
+ $acc_qty * ACCPRICE;
echo "Subtotal: $".number_format($totalamount,2)."<br />";
$taxrate = 0.10; // local sales tax is 10%
$taxvalue=($totalamount * $taxrate); // calculate tax amount
echo "Tax: $".number_format($taxvalue). "<br />"; // display tax amount
echo "Total including tax: $".number_format($totalamount + $taxvalue)."<br />";
echo "<p>Address to ship to is ".$address."</p>";
$outputstring = $date."\t".$shirt_qty." shirts\t".$pants_qty." pants\t".$skirt_qty." skirts\t".$shorts_qty." shorts\t".$acc_qty." accessories\t\$".$totalamount."\t". $address."\n";
// open file for appending
$fp = fopen("$DOCUMENT_ROOT/orders.txt", "ab");
flock($fp, LOCK_EX);
fwrite($fp, $outputstring, strlen($outputstring));
fwrite($fp, $outputstring);
flock($fp, LOCK_UN);
fclose($fp);
echo "<p>Order written.</p>";
?>
</body>
</html>