Home      Products & Services      Contact Us      Links

WebHatchers will design & develop your site for you.

Website Menu Heaven: menus, buttons, etc.

Send us your questions.

site search by freefind

SEO, Google, Privacy
   and Anonymity
Browser Insanity
Popups and Tooltips
Free Website Search
HTML Form Creator
Buttons and Menus
Image Uploading
Website Poll
IM and Texting
   or Not MySQL
Personal Status Boards
Content Management
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs

Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement

Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

PHP Guestbook Script

In the code below, we show one third of the code needed for a website guestbook. The code in which the sign-in data gets added to the database table is in the file add-a-guest-to-guestbook.php, explained in Script to Add a Guest to Guestbook. And the code in which the guestbook data gets viewed is in the file view-our-guestbook.php, explained in Script to View Our Guestbook.

According to wikipedia, "a guestbook is a paper or electronic means for a visitor to acknowledge their visitation to a site, physical or web-based, and leave their name, postal or electronic address (if desired), and a comment or note, if desired." Paper-based guestbooks are traditional in hotels, churches, at weddings, funerals, Bed and Breakfasts, museums and other private facilities. Even some private homes maintain guestbooks. Funeral homes maintain guestbooks and online memorials keep alive the memory of the dealy departed. Using guestbooks, you can build a sense of community with your site visitors and get feedback from these site visitors as well.

PHP Guestbook Sign-in

PHP Guestbook Viewing

In our PHP guestbook script, we first create the MySQL database table called guestbook if it doesn't exist. Then we confront the user with an HTML form that allows him or her to sign the guestbook. We considered getting and storing the ip addresses but rejected it—it can always be added later if there are users abusing the sign-in opportunity. We also rejected the idea of using a password. For one thing, we don't expect signers to return to this guestbook in the future. For another, it's an extra burden and we see little to gain since, again, they won't be returning. Even this could be added if indicated by future abuses. What we decided to do about spam signup bots is to include a captcha question that should bedevil any spammer, since one has to read a sentence and answer a question about it which would be very hard for a spambot, since the sentence is not made from text. It's an image, and a spambot would have to be able to read the text in an image, think about it, and figure out the answer and enter that in the form or the signup will fail. Others have done well with this safeguard.

In addition to spam-proofing the guestbook, we also used security measures to protect the MySQL database, but, like all such measures, they are NOT infallible. You'll learn more about these in the other 2 tutorial pages. We also put in validation scripts that ensure they don't enter too many characters, or unacceptable characters.

Now—on to the script code:

First we made sure the textarea input box did not get too many characters in it. We'll be trimming off excess when we get to MySQL table insertion anyway, but why not let the user know, in a friendly way, when they have put in the limit? This we did using the JavaScript textCounter() function specially designed for the job. The reason we didn't use a maxlength attribute in the textarea box like we did in the regular text input boxes is that they do not work. There is no HTML form command for character limitation for textarea boxes. So people are stuck with writing their own or finding one on the Internet—if they care. The textCounter() function counts the number of characters and displays how many you have left as you type and, coolest of all, once you reach 0 it won't let you stick any more characters in. If some wise guy turns off JavaScript and somehow manages to submit the form with more than 200 characters in the textarea box, the PHP action script that puts the text in the db will trim off the excess. Then come some PHP code. After using the config.php file to get the necessary magic words for db connection, we define a MySQL database guestbook table to hold the guestbook data. The table gets created only in it does NOT already exist.

Next we have the form. Most of the input boxes are standard stuff. Even the captcha answer input box is standard. It comes after the form displays the image of the question they'll need to get right. The textarea box has a onKeyDown event and a onKeyUp event, both of which run the textCounter() function to keep the character count limited to 200. Then there is a readonly input box—not for entry but for display—that shows how many characters you have left.

This file is named: PHP-guestbook.php

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>PHP Guestbook Script</TITLE>
<meta name="description" content="PHP Guestbook Script">
<meta name="keywords" content="PHP Guestbook Script,Guestbook Script,php,mysql,dhtml, DHTML">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit){field.value = field.value.substring(0, maxlimit);}
else{countfield.value = maxlimit - field.value.length;}}
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ddd}
p, td {font:13px Verdana; color:black;}
h1 {font:bold 40px Verdana; color:blue;text-align:center}
h2 {font:bold 13px Verdana; color:blue;text-align:center}



$sql="CREATE TABLE IF NOT EXISTS guestbook (
id int(4) NOT NULL auto_increment,
name varchar(42) NOT NULL default '',
email varchar(62) NOT NULL default '',
websiteURL varchar(62) NOT NULL default '',
comment longtext NOT NULL,
datetime varchar(42) NOT NULL default '',




<table width="654" border="1" align="center" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<td><b><h1>Please Sign Our Guestbook</h1></b></td>
<table width="650" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
<form id="form" name="form" method="post" action="add-a-guest-to-guestbook.php">
<table width="650" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">
<td align="right" width="190">Name: </td>
<td width="360"><input name="name" type="text" id="name" size="42" maxlength="42"></td>
<td width="50">&nbsp;</td>
<td align="right">Email: </td>
<td><input name="email" type="text" id="email" size="62" maxlength="62"></td>
<td width="50">&nbsp;</td>
<td align="right">Website URL: </td>
<td><input name="websiteURL" type="text" id="websiteURL" size="62" maxlength="62"></td>
<td width="50">&nbsp;</td>
<td align="right">Comment: </td>
<td><textarea name="comment" cols="40" rows="5" id="comment" onKeyDown="textCounter(this.form.comment,this.form.remLen,200)" onKeyUp="textCounter(this.form.comment,this.form.remLen,200)"></textarea></td><td valign='top'>
<input readonly type='text' name='remLen' size='3' maxlength='3' value="200"><br></td>
<td width="50">&nbsp;</td>
<td align="right">Captcha: </td>
<td><IMG SRC="login-question.png" WIDTH=294 HEIGHT=36 BORDER=0></td>
<td width="50">&nbsp;</td>
<td align="right">Answer: </td>
<td><input name="answer" type="text" id="answer" size="20" maxlength="42"></td>
<td width="50">&nbsp;</td>
<td valign="top">&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit" value="Reset"></td>
<td width="50">&nbsp;</td>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<td><b><h2><a href="view-our-guestbook.php">View Our Guestbook</a></h2></b></td>