Llamasery.com Home  
 
Server-side Tutorial/Article: Visitor Comments - Part 1 of 6
Alfie the alpha_geek: Llamasery guru-in-waiting Tutorials Purpose

Tutorials/Articles

Rate This
Visitor Comments
Feeling Secure
News & Events

Starter Tutorials

Starter Tutorials

Comments System

Assuming that you have a working knowledge of simple php and MySQL (acquired through the starter tutorials here, for example), adding a visitor comments system to your site is pretty simple.

The type of comments system we'll discuss and explain in this tutorial is one where a page of your site is displayed and at the bottom of the page are the comments which visitors have made (about the page content, we hope). As visitors add their own comment, these comments are automatically added to those displayed whenever anyone views that page. A three-line php snippet can be added to any page on your site where you want visitor comments 'active'.

In the conclusion of this tutorial we'll discuss options and enhancements, but for now let's begin with the basics. What we will need is:

  • A database table to contain comments and related information
  • A small form for visitors to add comments and provide additional information
  • A php form handler to abstract and process the form data and add it to our database
  • A short piece of php code to add to every page where you want the comments system active
First: Create the database table

For our example, we'll assume that we will ask for the visitor's name, location, and comments, and our form will automatically gather their IP address and the date & time they posted. Since we want their comments to be associated only with the page where they posted, we'll also collect a page ID of some sort.

The database table we'll be using will have the following data fields. If you are unfamiliar with the concepts of creating a database and initiating a database table, please refer to the starter tutorial entitled MySQL 101. Create that table from phpAdmin (via your site's Control Panel) and name the table page_comments

db field type/size extras
id tinyint (4) primary, auto-increment
name varchar (40)  
location varchar (40)  
comments text  
ip varchar (20)  
dated varchar (40)  
page_id tinyint (4)  

So far so good

We know exactly how we're going to approach this. We've established our database table, and now we need to create a form to acquire just that information.

  next  »