Hudzilla.org - the homepage of Paul Hudson
Contents > Practical PHP > Creating a guestbook Wish List | Report Bug | About Me ]

22.2.1     Analysis

This is NOT the latest copy of this book; click here for the latest version.

The goal of a guestbook is to capture a message from your visitors, as well as their name and email address, then display all that to visitors who can read your guestbook. Therefore, the most basic guestbook is going to look roughly like this:

GuestName

CHAR(255)

GuestEmail

CHAR(255)

GuestMessage

TEXT

DateSubmitted

INT

Naturally we will have an auto-incrementing ID primary key in there too, to enable us to work with individual records easily.

To handle both posting and reading messages, we will need two scripts: post.php and read.php. There are two ways we can choose when posting messages - we can use post.php to display the input form and handle saving it to our database and have it show a "Thanks for posting" message, or we can use read.php to handle saving the data to our database, which means users would immediately see their message live in the guestbook.

Which you choose to implement generally depends on your philosophy, and should match the behaviour seen elsewhere in your site. Webmasters who want every possible advert displayed will generally opt for the "Thanks for posting" scheme, as it generates one more page hit per use. Webmasters who are trying to conserve bandwidth or who do not care about adverts being displayed will generally opt to display the guestbook with the new post in there - as I said, it all depends on your philosophy.

It is fairly easy for you to switch between the two choices, so we will be going along with the "Thanks for posting" plan.

To handle posting to our guestbook we need post.php to have a name box, an email box, and a message text area. This is then submitted and entered directly into our database, and a thank you message is sent back along with a link to read.php. All clear? Let's get programming...





<< 22.2 Creating a guestbook   22.2.2 Development >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
shafa_butterfly@yahoo.com - 07 Sep 2008

i am confuse

A PHP User - 07 Sep 2008

<a href="http://www.google.com">well</a> done http://www.google.com



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is eight plus five?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow