Jump to content

link to results rather than automatically display


DanielHardy

Recommended Posts

Hi,

 

I have the following guestbook code up and running perfectly. However, the guestbook area currently occupies a small area on an already full page. I was hoping for guidance on how I would go about displaying the first say 5 results, and then offerring a link to a page that would display all of the results. Any sort of help is appreciated.

 

<?php
// Save filename to variable.
$guestbook = "messages.txt";

// This will run if someone sends user input.
if (isset($_POST['button']))
{
	// Check whether any fields are empty or not.
	if (!empty($_POST['name'])  && !empty($_POST['message']))
	{
		// Bad characters in E-Mail string.
		$badSearch = array("@", ".");
		// Goods characters in E-Mail string.
		$goodSearch = array(" @ ", " . ");
		// Grab name from the form and add a newline afterwards.
		$string .= "<b>" . $_POST['name'] . "  ";
		// Grab email and replace the @ and . in the string.
		$string .= str_replace($badSearch, $goodSearch, $_POST['email']) . "</b>\n";
		// Grab the message and save it in $string.
		$string .= "<font color=#2766c5>" . $_POST['message'] . "</font>\n<hr>";

		// Open messages.txt and append more posts to it.
		$file = fopen($guestbook, "a");
		// Write $string to the text file and replace bad characters to avoid XSS attacks.
		fwrite($file, nl2br(strip_tags($string, "<b><hr><font>")));
		// Close the file we opened.
		fclose($file);
		echo '<script>alert("Your comment has been added ")</script>';
	} else {
		// Of the form fields are empty will there popup a message.
		echo '<script>alert("Please fill out the whole form")</script>';
	}
}

// This will read the file and print out everything in the text file.
// Open and read the messages.txt file.
$readfile = fopen($guestbook, "r");
// Read and print out everything in the page.
echo @fread($readfile, filesize($guestbook));
// Close the file we opened.
fclose($readfile);

?>

 

Thanks

 

Dan

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.