Jump to content
Sign in to follow this  
Xtazy

Guestbook

Recommended Posts

anyone knows how can I create a guestbook using HTML so that I can fit it in my website? I don't want a website where I can make free guestbooks, i want smth to put in an html page on my website...thanx, xtazy

Share this post


Link to post
Share on other sites

You can make a simple guestbook using a little php or any other server side scripting language.Search "simple php guestbook" in google, you should find what you're looking for.:)

Share this post


Link to post
Share on other sites

ok, so i have found smth....now, i have three PHP files: addbook.php, readbook.php and postform.php, and a .txt file: guestbook.txt.The codes are:addbook.php :

<?php if ($message != '')  {  $message = str_replace ("\n","<br>",$message);  $message = strip_tags ($message, '<br>');  $newRow = '<div class="viewGuestbook">' . ($message) .		  '<br>' . date('d.m.Y H:i') . ' - ' . strip_tags ($name) .		  '</div>';			  $oldRows = join ('', file ('guestbook.txt') );  $fileName = fopen ('guestbook.txt', 'w');  fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows);  fclose ($fileName); }  include ("readbook.php");?>

readbook.php :

<div class="guestbookTop"><a href="postform.php">Write</a> to a guestbook<br><br></div><?php $fileName = file ("guestbook.txt"); $rows = count ($fileName);   if ($rows > 10) { 	if (!isset ($row) ) 	{ 		$row = 0; 	}  	print ("<table class=\"guestbookLinks\"><tr><td width=\"50%\">");   	if ($row > 0) 	{		echo "<div class=\"nextPage\"><< <a href=\"readbook.php?row=" . ($row - 10) . "\">Next 10</a></div>";	}		print ("</td><td width=\"50%\">"); 	if ( ($rows - $row) > 10) 	{		echo "<div class=\"previousPage\"><a href=\"readbook.php?row=" . ($row + 10) . "\">Previous 10</a> >></div>";	}			print ("</td></tr></table>");   	for ($i = $row; $i < ($row + 10); $i++)	{		echo $fileName [$i];	} } else {	  for ($i=0; $i < $rows; $i++)	  {		  echo $fileName [$i];	  } }  ?><div class="guestbookUp"><br><br><br><br>	<a href="postform.php">Write</a> to a guestbook</div>

postform.php :

<div class="normalText"><form action="addbook.php" method="post">Message<br><br><textarea name="message" cols="50" rows="7" class="textbox"></textarea><br><br>Name<br><br><input type="text" name="name" size="48" class="textbox"><br><br><input type="submit" value=" Submit " class="textbox"></form></div>

when i access this address: http://86.104.117.159:32167/addbook.php , I receive this error:

Notice: Undefined variable: message in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\addbook.php on line 2
so this means that this line is broke:
if ($message != '')

and i should type something between ' and '...but what? i'm a beginner in PHP, so I don't know lots about it...when you see this message, my website could be open, so you should access this addresses and see for yourself:http://86.104.117.159:32167/addbook.phphttp://86.104.117.159:32167/readbook.phphttp://86.104.117.159:32167/postform.php10x a lot,xtazy

Share this post


Link to post
Share on other sites

The error

Notice: Undefined variable: message in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\addbook.php on line 2
Means that $message is not set to anything, as in it has no value. You don't need to type anything between the quotation marks, as that is just to test whether there is a message (e.g. is the message does not look like it has nothing in it then...). The problem its that there is a line missing from addbook.php, it should be
<?php$message = $POST['message'];if ($message != ''){  $message = str_replace ("\n","<br>",$message);  $message = strip_tags ($message, '<br>');  $newRow = '<div class="viewGuestbook">' . ($message) .		  '<br>' . date('d.m.Y H:i') . ' - ' . strip_tags ($name) .		  '</div>';			  $oldRows = join ('', file ('guestbook.txt') );  $fileName = fopen ('guestbook.txt', 'w');  fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows);  fclose ($fileName);}include ("readbook.php");?>

But - you shouldn't be linking to addbook.php anyway, that is the script to add a message. To just view the messages, use readbook.php

Share this post


Link to post
Share on other sites

when i put that code in my addbook.php, i receive this error:

Notice: Undefined variable: POST in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\addbook.php on line 2
and when i post a message using the postform, i can't see it in readbook.php ...

Share this post


Link to post
Share on other sites

Drat sorry typo (I seem to be making a lot of those lately :) ) the second line should be

$message = $_POST['message'];

Share this post


Link to post
Share on other sites

Yeah, that did it...but it looks like the line 9 was broken as well, but I managed to fix it...i mean this one:

'<br>' . date('d.m.Y H:i') . ' - ' . strip_tags ($name) .

but instade of $name, it should be $message...anyway, thanx a lot, it's really appreciated...Xtazy!

Share this post


Link to post
Share on other sites

nope, that code was broken too, this one is correct, i'm sure of it:

<?php(isset($_POST['message']))?$message=$_POST['message']:$message='';(isset($_POST['name']))?$name=$_POST['name']:$name=""; if ($message != ''){  $message = str_replace ("\n","<br>",$message);  $message = strip_tags ($message, '<br>');  $newRow = '<div class="viewGuestbook">' . ($message) .		  '<br>' . date('d.m.Y H:i') . ' - ' . strip_tags ($name) .		  '</div>';		     $oldRows = join ('', file ('guestbook.txt') );  $fileName = fopen ('guestbook.txt', 'w');  fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows);  fclose ($fileName);}include ("readbook.php");?>

i added this two lines:(isset($_POST['message']))?$message=$_POST['message']:$message='';(isset($_POST['name']))?$name=$_POST['name']:$name=""; instead of$message = $_POST['message'];and this line is good:'<br>' . date('d.m.Y H:i') . ' - ' . strip_tags ($name) .$name is correct, $message was broken...instead of name tou get your message...duh! :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...