Do you want to encourage your visitors to say hi when they visit your friendly Website? This tutorial is divided in 4 phases and will teach you how to create a simple PHP guestbook using only one PHP file.
We will create the PHP/MySQL Guestbook in four phases
- Setting up the database
- Creating the Guestbook form
- Coding the PHP script that will process the guestbook submissions
- Coding the PHP script that will display the guestbook entries
1. Setting up the database
The table’s name will be guestbook. We are going to setup the following columns:
- id – the unique identifier for a guestbook entry
- name – the visitor’s name
- email – the visitor’s email
- comments – the message
- datetimecreated – to record the date and time the visitor submitted an entry
If you haven’t created a database yet, using whatever interface you use for working with MySQL databases, you can execute the following command to create a database.
CREATE DATABASE mywebsite;
You can execute the following command to create our guestbook table.
CREATE TABLE guestbook
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name TEXT,
email TEXT,
comments TEXT,
datetimecreated DATETIME NOT NULL
);