I am brand new to using PHP and I have been trying to write a simple guestbook that writes to a flat file. All I can get it to do so far, is send me my "friendly error message" saying that it failed to create/write to the flat file.
I initially thought this was a problem with my WAMP implementation, so I tried this on my PHP webhosting account as well, same thing. I have attached the code below, any suggestions for the noob? 😕
<?php
// create short variable names
$username = $POST['username'];
$eaddress = $POST['eaddress'];
$comments = $_POST['comments'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Guestbook Submission Process</title>
</head>
<body>
<?php
$outputstring = $username." username \t".$eaddress." eaddress \t".$comments." comments \t";
// open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/../guest/guest.txt", 'ab');
if (!$fp)
{
echo '<p>Someone broke it again. </p>';
exit;
}
fwrite($fp, $outputstring, strlen($outputstring));
fclose($fp);
echo '<p>Succes! </p>';
?>
</body>
</html>