Can't write to a file.

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
@ $fp = fopen("$DOCUMENT_ROOT/../test/orders.txt", 'ab');

if (!$fp) {
	echo "<p><strong> Your order could not be processed at this time.  Please try again later.</strong></p></body></html>";
	exit;
}

flock($fp, LOCK_EX);
	
fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);

echo "<p>Order written.</p>";

?>

Is there any error? If not try removing the @ from in front of the fopen function since that is stopping errors from showing.

Like:
[php]
echo “

Total of order is $”.$totalamount."

";
echo “

Address to ship to is “.$address.”

”;

$outputstring = $date. “\t”.$tireqty." tires \t".$oilqty." oil\t".$sparkqty." spark plugs\t$".$totalamount."\t". $address."\n";

// open file for appending
$fp = fopen(“orders.txt”, ‘ab’);

if (!$fp) {
echo "

Your order could not be processed at this time. Please try again later.

";
exit;
}

flock($fp, LOCK_EX);

fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);

echo “

Order written.

”;
?> [/php]

It is most likely a permissions issue.

I get this error after removing the @ sign

Warning: fopen(/test/orders.txt) [function.fopen]: failed to open stream: No such file or directory in /home/jbishop/public_html/test/processorder.php on line 64

the file is located at allcamchat.com/test/orders.txt

Since the script is in the same directory as the text file, try changing:
[php]$fp = fopen("$DOCUMENT_ROOT/…/test/orders.txt", ‘ab’);[/php]
to:
[php]$fp = fopen("./orders.txt", ‘ab’);[/php]
Does that work?

that worked thank you so much.

Sponsor our Newsletter | Privacy Policy | Terms of Service