Jump to content


Photo
- - - - -

GUEST BOOK


  • Please log in to reply
3 replies to this topic

#1 fgd46tgh7ddd

fgd46tgh7ddd

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Female

Posted 12 September 2005 - 03:24 PM

¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
A SIMPLE PHP GUEST BOOK BY NRGPRO
Copy And Paste :lol:
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
<?php

// SIMPLE PHP Guestbook BY NRGPRO
// [email protected]
// http://www.NRG-Pro.com

// Error?
$error = false;

// Sign Guestbook
function signGuestbook(){
         // gain access to the global form variables
        global $name,$email,$webpage,$comments;

        // put a new guestbook entry together
        $new_guestbook_entry = urlencode($name).",".urlencode($email).",".urlencode($webpage).",".urlencode($comments)."\n";

        // write the new guestbook entry to
        // the guestbook data file
        $fp=fopen("guestbook.data",a) or exit;
        fwrite($fp,$new_guestbook_entry);
        fclose($fp);

	// reset form variables
	$name="";
	$email="";
	$webpage="";
	$comments="";
}

function readGuestbook(){

         // Read Data
        $fp=fopen("guestbook.data",r) or exit;
        $rawdata=fread($fp,filesize("guestbook.data"));
        fclose($fp);

	// Guestbook is Empty
	if($rawdata == ""){
  echo "<p><font face=\"sans-serif\">No Entries!</font></p>";
  return;
	}

        // Array Element
        $each_line = explode("\n",$rawdata);

	// Sort By Newest
	rsort($each_line);

	// Guestbook is Not Empty
	$entries = count($each_line)-1;
	echo "<p><font face=\"sans-serif\">Entries :<b>$entries</b> entries</font></p>";

        // Step Through Each Guestbook Entry
        for ($key = 0; $key < count($each_line)-1; $key++){

                $temp = explode(",",$each_line[$key]);

                $guestbook[$key]["name"] = $temp[0];
                $guestbook[$key]["email"] = $temp[1];
                $guestbook[$key]["webpage"] = $temp[2];
                $guestbook[$key]["comments"] = $temp[3];
        }

        // Entries In the Guestbook
        for($key = 0; $key < count($guestbook); $key++){
                echo "<p><font face=\"sans-serif\"><b>Name:</b> ";
                echo htmlspecialchars(urldecode($guestbook[$key]["name"]));
                echo "<br><b>Email:</b> ";
                echo "<a href=\"mailto:";
                echo addslashes(urldecode($guestbook[$key]["email"]));
                echo "\">";
                echo htmlspecialchars(urldecode($guestbook[$key]["email"]));
                echo "</a><br><b>Webpage:</b> ";
                echo "<a href=\"";
                echo addslashes(urldecode($guestbook[$key]["webpage"]));
	echo "\">";
                echo htmlspecialchars(urldecode($guestbook[$key]["webpage"]));
                echo "</a><br><b>Comments:</b> ";
                echo htmlspecialchars(urldecode($guestbook[$key]["comments"]));
                echo "</font></p>";
        }
}

// Check for Values
if ($sign_guestbook){
        if($name != "" && $email != "" && $webpage != "" && $comments != ""){
                signGuestbook();
        }else{
                $error = true;
        }
}

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>My PHP Guestbook</title>
</head>

<body>
<p>
  <?php if($error){ ?>
  <?php } ?>
</p>
<form name=guestbook method="post" action="guestbook.php">
<div align="left">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top" align="left"><font face="sans-serif">Name:</font></td>
<td valign="top" align="left"><input type="text" name="name" size="70" value="<?php echo addslashes($name); ?>"></td>
</tr>
<tr>
<td valign="top" align="left"><font face="sans-serif">Email:</font></td>
<td valign="top" align="left"><input type="text" name="email" size="70" value="<?php echo addslashes($email); ?>"></td>
</tr>
<tr>
<td valign="top" align="left"><font face="sans-serif">Webpage:</font></td>
<td valign="top" align="left"><input type="text" name="webpage" size="70" value="<?php echo addslashes($webpage); ?>"></td>
</tr>
<tr>
<td valign="top" align="left"><font face="sans-serif">Comments:</font></td>
<td valign="top" align="left"><textarea rows="5" name="comments" cols="61" wrap=virtual><?php echo htmlspecialchars($comments); ?></textarea></td>
</tr>
<tr>
<td valign="top" align="left"></td>
<td valign="top" align="left"><input type="hidden" name="sign_guestbook" value="true"><input type="submit" value="Submit"> <input type="reset" value="Reset"></td>
</tr>
</table>
</div>
</form>

<p>
  <?php readGuestbook(); ?>
</p>
</body>
</html>

Edited by Donna, 16 September 2005 - 08:08 PM.

  • tingying likes this

#2 chewx

chewx

    Young Padawan

  • Members
  • Pip
  • 15 posts
  • Location:NOTTINGHAM, UK

Posted 20 February 2006 - 09:23 AM

ok, with this code is there any way to slightly change it so that if a user is logged in the name field is there name and if not logged in its just a blank box..?

#3 liveman

liveman

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Location:New Jersey

Posted 09 March 2006 - 02:01 PM

assume you having sessisons change
<td valign="top" align="left"><input type="text" name="name" size="70" value="<?php echo addslashes($name); ?>"></td>
to
<td valign="top" align="left"><input type="text" name="name" size="70" value="<?php echo $_SESSION['username']; ?>"></td>
That would be the concept

#4 Paint

Paint

    Young Padawan

  • Members
  • Pip
  • 88 posts

Posted 14 March 2006 - 12:01 PM

Cool guestbook! Although, this is not a tutorial... and, it is in the tutorial section.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users