Jump to content

Guestbook


Xtazy

Recommended Posts

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

Link to comment
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

Link to comment
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 ...
Link to comment
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'];

Link to comment
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!

Link to comment
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! :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...