Click to See Complete Forum and Search --> : more guestbook help


derezzz
10-27-2003, 01:11 PM
Hey
I am about 2 hours away from a deadline and i am just now able to test the php for the guestboook that I cut and pasted from the very helpful Pyro, but I think maybe i messed it up...i dont know. Its giving me an error on line 17, it says "Warning: fopen("guestbook.txt", "") - Invalid argument in /narrativesite/narrative1.php on line 17
Your entry could not be added."
does anyone know how I can fix this? My code is as follows (I didnt change THAT much from the orinal which i found on page two of this forum.

<?PHP

$filename = "guestbook.txt"; #CHMOD to 666
$text = "";

if (isset($_POST["submit"])) {
$name = htmlspecialchars($_POST["name"]);
$message = htmlspecialchars($_POST["message"]);

$date = date ("l, F jS, Y");
$time = date ("h:i A");

$value = $message."<br>\n<span style=\"font-family: helvetica, arial, sans-serif; font-size: 70%; font-weight: bold;\">added to by $name at $time on $date.</span>\n<break>\n";

##Write the file##

$fp = fopen ($filename, "a");
if ($fp) {
fwrite ($fp, $value);
fclose ($fp);
}
else {
echo ("Your entry could not be added.");
}
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script language="JavaScript">
var good;
function checkEmailAddress(field) {
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail) {
good = true;
}
else {
alert('Please enter a valid e-mail address.');
field.focus();
field.select();
good = false;
}
}
u = window.location;
m = "I thought this might interest you...";
function mailThisUrl() {
good = false
checkEmailAddress(document.eMailer.address);
if (good) {
window.location = "mailto:"+document.eMailer.address.value+"?subject="+m+"&body="+document.title+" "+u;
}
}
</script>
<script language="javascript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
</script>
<title>Interactive Narrative</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
<!--
body {
font-family: helvetica, arial, sans-serif;
background-color: #E1E0E0;
}
-->
</style>
</head>
<body>
<br>
<br>
<br>
<table align="center" border="0" cellpadding="2" bgcolor="#00CCFF" width="100%">
<tr>
<td width="50%">
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post">
<p>&nbsp;add your narrative:<br><br>
<textarea name="message" rows="10" wrap="physical" cols="65" onKeyDown="textCounter(this.form.message,this.form.remLen,300);"
onKeyUp="textCounter(this.form.message,this.form.remLen,300);"></textarea>
<br>
<input readonly type="text" name="remLen" size="7" maxlength="3" value="300">
<br>
<br>

&nbsp;your name: <input type="text" name="name" size="25">
<input type="submit" name="submit" value="post your narrative"></p>
</form>
</td>
<td width="3%">&nbsp;</td>
<td width="47%" valign="top">
I once got drunk and fell down. When I couldn't get back up again I decided to talk to an old news paper lying next to me.
When the newspaper didn't have a whole lot to say I decided to talk to the trashcan on the other side of me.
"I don't understand why you can empty me more often. You take everything you don't want and give it to me. Who says I
want it, you don't want it, why should I? Do you know what it is like having all this smelly gross garbage inside of you?"<br><br>
<?PHP

$contents = @file($filename) or die("No files in guestbook.");

foreach ($contents as $line_num => $line) {
$text .= $line;
}

$text = split("<break>", $text);

for ($i=0; $i<count($text)-1; $i++) {
echo "<div style=\"border: gray 1px solid; padding: 5px; font-family: helvetica, arial, sans-serif; background-color: #E1E0E0;\">";
echo $text[$i];
echo "</div>";
}

?>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" colspan="3">
<form name="eMailer">
continue the narrative by sending it to someone,
enter their e-mail address below
<br>
<br>
<input type="text" name="address" size="25">
<br>
<input type="button" value="pass the narrative on" onClick="mailThisUrl();">
</form>
</td>
</tr>
</table>
<a href="index.html"><img src="back.gif" border="0"></a>
</body>
</html>

pyro
10-27-2003, 03:48 PM
Did you CHMOD the file to 666 (on *nix servers) or make sure it wasn't read-only (on win servers)?

the-FoX
10-28-2003, 01:37 AM
on line 17 you use fopen($filename....,"a"); but the error message shows, that there is no "a"?!
try using a+ instead