Help - Search - Members - Calendar
Full Version: Php Guestbook
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
jason846
Okay, this is the PHP guestbook i am trying to put on my website, but i can't figure something out (see bottom):

CODE
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="">
Name:
<input type="text" name="name" size="30">
<br>
E-mail:
<input type="text" name="email" size="30">
<br>
<br>
Message:
<textarea name="message" wrap="VIRTUAL" cols="30" rows="4"></textarea>
<br>
<br>
Homepage URL:
<input type="text" name="homepageurl" size="30" value="http://">
<br>
<br>
Homepage Name:
<input type="text" name="homepagename" size="30">
<br>
<br>
<input type="hidden" name="from" value="<? echo $HTTP_REFERER ?>">
<br>
<input type="submit" name="Submit" value="Submit">
</form>

<!-- start php code -->

<?
if ($message)
{
$name = strip_tags($name);
$email = strip_tags($email);
$homepageurl = strip_tags($homepageurl);
$homepagename = strip_tags($homepagename);
$message = strip_tags($message);
$message = ereg_replace("\r\n\r\n", "\n<P>", $message);

if (get_magic_quotes_gpc())
{
$message = stripslashes($message);
$name = stripslashes($name);
}

$date = date("l, F j Y");
$message = "<B>$name </B> -- $date -- <a href=mailto:$email>$email</a><br>$message<br><a href=$homepageurl>$homepagename</a><br>Refered by $from<br><br>\r\n";

$textfile = "guestbook.txt";
if ($fp = @fopen ($textfile, "r"))
{
$oldmessages = @fread($fp,filesize($textfile));
@fclose(fp);
}

$fp = fopen ($textfile, "w");
fwrite ($fp, $message);
fwrite ($fp, $oldmessages);
fclose ($fp);
}
@readfile("guestbook.txt");
?>

<!-- end php code -->

</body>
</html>


(with .PHP file extension) and i get a error saying:

" Notice: Undefined variable: message in /www/zzl.org/t/x/s/txstormchasers/htdocs/guestbook.php on line 36 "



Any help?
swordz
Line 36 is:

if($message){

$message has not yet been defined. This is what the notice tells you.

What you really want is:
if(isset($message)){

swordz
jason846
Thanks so much! but when i add a new entry, it should save that entry to the text file " guestbook.txt " and then it should read that file within the guestbook, and its reading the file fine, but when i add a new entry its not adding the info to the text file for the guestbook to read.

How would i fix this?

EDIT: actually, i renamed the file to entries.txt, and renamed it within the guestbook, so that has nothing to do with it, and Yes, i did CHMOD it to 777. and for testing reasons, the link to this is http://txstormchasers.zzl.org/guestbook.php
Thanks!
~jason
herb2006
QUOTE(jason846 @ Oct 13 2009, 01:24 AM) *
Thanks so much! but when i add a new entry, it should save that entry to the text file " guestbook.txt " and then it should read that file within the guestbook, and its reading the file fine, but when i add a new entry its not adding the info to the text file for the guestbook to read.

How would i fix this?

EDIT: actually, i renamed the file to entries.txt, and renamed it within the guestbook, so that has nothing to do with it, and Yes, i did CHMOD it to 777. and for testing reasons, the link to this is http://txstormchasers.zzl.org/guestbook.php
Thanks!
~jason


your guestbook.php is working well, it can add the info to the text file.
but it is enough to CHMOD a file to 0666, a folder to 0777.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.