NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Simple GuestBook

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
6 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 07-24-2005, 12:00 AM THREAD STARTER               #1 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics

Simple GuestBook


A simple guestbook. Stores information in a text file.
EDIT: Script Updated. Now v1.0.2

If you have any problems with this script, i.e. Any errors. Or, if you have any suggestions, PM or reply to this thread.

-Tweaked the code a lil.
-Few minor bugs fixed.

guestbook.php (Displays Entries)
PHP Code:
<html>
<head>
<title>Guestbook</title>
</head>

<body>
<?php

$file 
"guestbook.txt";
if(
file_exists($file))
{
  
$fp fopen($file"r");
  
$book fread($fpfilesize($file));
  
fclose($fp);
  echo 
nl2br($book);
}
else
{
  echo 
"Sorry, seems there was an error, please wait a few minutes and try again.";
}
?>
</body>
</html>
addentry.html (The form)
HTML Code:
<html>
<head>
<title>Add an Entry</title>
</head>

<body>

<form method="post" action="addentry.php">
Name:
<br>
<input name="name" type="text" size="30" maxlength="40">
<br><br>
Email:
<br>
<input name="email" type="text" size="30" maxlength="40">
<br><br>
Home Page:
<br>
<input name="site" type="text" size="30" value="http://" maxlength="40">
<br><br>
Message:
<br>
<textarea name="message" cols="25" rows="5">
</textarea>
<br><br>
<input type="submit" value="Add">
</form>

</body>
</html>
addentry.php (what the form submits the information to)
PHP Code:
<html>
<head>
<title>Thank You</title>
</head>

<body>
<?php

$file 
"guestbook.txt";
$name $_POST['name'];
$email $_POST['email'];
$site $_POST['site'];
$message $_POST['message'];
$date date("l dS of F Y h:i:s A");

$site trim(stripslashes(strip_tags($site));
$message trim(stripslashes(strip_tags($message));
$email  trim(stripslashes(strip_tags($email));
$name trim(stripslashes(strip_tags($name)));
????: NamePros.com http://www.namepros.com/code/109338-simple-guestbook.html


if(empty(
$email) || empty($name) || empty($message))
{
  echo 
'Sorry all fields are required.';
}
else
{
  
$validate preg_match('/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/';, $email);

  if(!
$validate)
  {
    echo(
$email "is not a valid email!");
  }
  else
  {
    
$e $email;
  }
  if(
file_exists($file))
  {
    
$fp fopen($file"a");
    
fwrite($fp'
    <font size="4">
    <br><br><br>
    Name: '
.$name.'<br>
    Email: '
.$e.'<br>
    Home Page: <a href="'
.$site.'">'.$site.'</a><br>
????: NamePros.com http://www.namepros.com/showthread.php?t=109338
    Message: '
.$message.'<br><br>
    Added: '
.$date.'</font>
    '
);
    
fclose($fp);
    echo 
'<p align="center">Thank you '.$name.' for singing my guestbook</p>';
  }
  else
  {
    echo 
'Sorry, seems there was an error, please try again in a few minutes.';
  }
}
?>

</body>
</html>
edit.php (where you can edit/delete entries)
PHP Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Admin Area</title>
</head>

<body>
<form method="post" action="?do=login">
<b>Password Required</b>
Admin Username: <input type="text" name="user" size="20">
Admin Password: <input type="password" name="pass" size="20">
<input type="submit" value="Submit">
</form>
<br>
<?php

//I recommend you change the username and password.
$username "admin";
$password "password";

if(
$do == "login")
{
  if(
$_POST['user'] == $username && $_POST['pass'] == $password)
  {
    echo 
"Login successful.";
    echo 
"<br>";
    echo 
"<br>";

    
$file "guestbook.txt";
    if(
file_exists($file))
    {
      
$fp fopen($file"r");
      
$book fread($fpfilesize($file));
      
fclose($fp);
    }
?>
<form method="post" action="?do=edit">
<b>If you wish to edit/delete an entry, edit below:</b>
<br>
<textarea name="entries" cols="70" rows="20">
<?php
echo $book;
?>
</textarea>
<br>
<input type="submit" name="Submit" value="Save">
<input type="button" name="Cancel" value="Cancel" onclick="javascript: history.back()">
</form>
<br>
<br>
<?php
  
}
  else
  {
    echo 
"<font color=\"red\">Invalid Username or Password.</font><a href='javascript: history.back()'>Try again.</a>";
  }
}
if(
$do == "edit")
{
  
$entries $_POST['entries'];
  
$entries trim(stripslashes($entries));
  
$file "guestbook.txt";

  if(
file_exists($file))
  {
    
$fp fopen($file"w");
    
fputs($fp$entries);
    
fclose($fp);
?>
<br>
<br>
Content Edited Successfully.
<?php
  
}
}
?>

</body>
</html>
guestbook.txt (Where the entries are stored) - Just upload a blank .txt file. Also.. It has to be writable. CHMOD 0777


Enjoy
Last edited by SecondVersion; 11-22-2005 at 08:08 AM.
Eric is offline  
Old 09-13-2005, 12:08 AM   #2 (permalink)
NamePros Member
Join Date: Sep 2005
Location: Ontario Canada
Posts: 181
whiteknight will become famous soon enoughwhiteknight will become famous soon enough
 


Animal Rescue Breast Cancer Diabetes Save a Life 9/11/01 :: Never Forget
I have a small problem with mine when you go to view the entries the html code popes up also how would you delete them if there are any negative ones?

http://www.kvchosting.com/code/addentry.html - my version of your code
whiteknight is offline  
Old 09-13-2005, 02:21 AM   #3 (permalink)
NamePros Member
Join Date: Sep 2005
Location: Ontario Canada
Posts: 181
whiteknight will become famous soon enoughwhiteknight will become famous soon enough
 


Animal Rescue Breast Cancer Diabetes Save a Life 9/11/01 :: Never Forget
nm got it working thanks for the script
whiteknight is offline  
Old 09-13-2005, 02:54 AM THREAD STARTER               #4 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
I'll edit the post in a sec. Here in a min, i'll write a page so ou can edit the guestbook etc..


-Eric
Eric is offline  
Old 09-13-2005, 04:23 AM   #5 (permalink)
NamePros Member
Join Date: Sep 2005
Location: Ontario Canada
Posts: 181
whiteknight will become famous soon enoughwhiteknight will become famous soon enough
 


Animal Rescue Breast Cancer Diabetes Save a Life 9/11/01 :: Never Forget
Is there a way how u can make it so if u wanted to delete negative entries you can do it without having to delete the .txt and re-uploading it and chmoding it?
whiteknight is offline  
Old 09-13-2005, 04:48 PM THREAD STARTER               #6 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Script Updated in First Post. Will add the edit/delete page in a lil bit.

Edit/Delete page added.
Eric is offline  
Old 09-14-2005, 08:52 PM   #7 (permalink)
AJ
NamePros Regular
Join Date: Jun 2005
Location: Indiana, USA
Posts: 391
AJ is a jewel in the roughAJ is a jewel in the roughAJ is a jewel in the rough
 



Ive got this up and running on my site (http://scoville-jenkins.com/guest_book/guestbook.php). Seems to work really well! I did add a link to the add entry page on the main page and then I added a link back to the main page on the thank you page, since those pages didnt have links back already. And I also aint got the edit page up since I wasnt quite sure how to work it lol. Anyways... as I said, works great! Thanks SV!
AJ is offline  
Old 09-15-2005, 03:50 AM   #8 (permalink)
NamePros Member
Join Date: Sep 2005
Location: Ontario Canada
Posts: 181
whiteknight will become famous soon enoughwhiteknight will become famous soon enough
 


Animal Rescue Breast Cancer Diabetes Save a Life 9/11/01 :: Never Forget
AJ how did u get it so that you can click on the links rather then copy and paste them into your browser like i have done here - http://www.kvchosting.com/code/addentry.html
whiteknight is offline  
Old 09-16-2005, 02:27 AM THREAD STARTER               #9 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by AJ
Ive got this up and running on my site (http://scoville-jenkins.com/guest_book/guestbook.php). Seems to work really well! I did add a link to the add entry page on the main page and then I added a link back to the main page on the thank you page, since those pages didnt have links back already. And I also aint got the edit page up since I wasnt quite sure how to work it lol. Anyways... as I said, works great! Thanks SV!

????: NamePros.com http://www.namepros.com/showthread.php?t=109338
Hello AJ,

Thanks, I'm glad you like it. The edit page, just upload to your server, then go to http://www.yourdomain.com/path/to/edit.php Enter user and pass, then you can delete/edit entries.

Psssssst, I'm working on a SQL version.

-Eric
Eric is offline  
Old 10-09-2005, 06:26 PM   #10 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: U.S.A.
Posts: 655
Coolprogram has a spectacular aura aboutCoolprogram has a spectacular aura about
 



Dam nice sript SV heck i may even use it.Know what i will use it.
Coolprogram is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Simple site management with the use of PHP and the query string(?page=1) deadserious Webmaster Tutorials 8 10-09-2004 01:20 PM
Guestbook form??? majinfaisal Web Design Discussion 7 08-14-2004 12:10 AM
Tutorial: Creating a simple cgi hit counter for your site using Perl deadserious Webmaster Tutorials 3 05-29-2004 01:31 AM

 
All times are GMT -7. The time now is 02:08 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger