In Part 5 of the Easy PHP Guestbook tutorial we will cover retrieving the inserted data from the database and displaying it in a browser.

Create a new file and call it viewguestbook.php, open this file and put the following code in it.

$entriesq = mysql_query(“select * from guestbookentries”);
while($entriesr = mysql_fetch_array($entriesq)){
     $name = $entriesr["name"];
     $date = $entriesr["date"];
     $website = $entriesr["website"];
     $entry = $entriesr["entry"];
     echo “<tr><td>Name:</td><td>” . $name . “</td></tr>”;
     echo “<tr><td>Date:</td><td>” . $date . “</td></tr>”;
     echo “<tr><td>Website:</td><td>” . $website . “</td></tr>”;
     echo “<tr><td>Entry:</td><td>” . $entry . “</td></tr>”;

After you’ve made a few entries using the form from part 3 combined with the added code from part 4, you should be able to run this script and it should display all the entries that were inserted. Hopefully this was helpful to some. In the next few days I will be posting a download that has all these files with all of the source code as well as creating an advanced guestbook that can be purchased.

In Part 4 of the Easy PHP Guestbook tutorial we will cover creating the inserting data into the database that was filled out in the user submission form.

Open the guestbookform.php file from part 3 and put the following code in it at the very top of the file:

     $name = $_POST["guestbookname"];
     $date = time();
     $website = $_POST["guestbookwebsite"];
     $entry = $_POST["guestbookentry"];
     mysql_query(“insert into guestbookentries (name,date,website,entry) values (‘$name’,’$date’,’$website’,’$entry’)”);
echo “Your entry has been submitted”;

This part of the script does 3 things, it checks to see if the submit button has been pressed, if it has then it assigns the values from the submission form to variables, and then takes those variables and inserts them into the database. Finally it will output a message stating that the entry has been successfully entered into the database.

This concludes Part 4 of the tutorial, in Part 5 we will cover how to display the entries that are in the database. Part 5 will also be the last part of the tutorial at which point I will make a more advanced guestbook script along with an admin section to manage entries and will sell it on this site for $5.00

In Part 3 of the Easy PHP Guestbook tutorial we will cover creating the user submission form for our guestbook.

Create a new file and call it guestbookform.php and put the following code in it:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF8″ />
<title>My Guestbook</title>

<form action=”” method=”post”>
<input type=”text” name=”guestbookname” id=”guestbookname” />
<br />
<input type=”text” name=”guestbookwebsite” id=”guestbookwebsite” />
<br />
<textarea name=”guestbookentry” id=”guestbookentry” cols=”45″ rows=”5″></textarea>
<br />
<input type=”submit” name=”submit” id=”submit” value=”Submit” />

Save the file and upload it to your guestbook folder that you created on the server from the previous tutorial. You can point your browser to http://yourservername.com/guestbook/guestbookform.php

You should see the form with a spot to write a name, website and an entry, as well as a submit button. This file as it is now will not perform any functions, in part 4 we will cover how to take the values that a user would fill in and store them in the database.

This concludes Part 3 of the tutorial.

In this part of the tutorial I will cover briefly how to setup a new database and create the php file that will have the database connection strings.

First things first, create a new database and name it guestbook, assign a new user to this database name the new user guestbook, assign a password for this user 12345 will work for now.

Creating databases and assigning users will not be covered in this tutorial, this should be covered in a help file provided by your hosting company.

Once your database has been created and a user has been added you will need to setup the tables that will store each guestbook entry.

For starters lets create a table and call it guestbookentries

You will need 5 columns in this table:

  1. guestbookentryid – Set this column as the primary key and set it to auto increment, the type will be BIGINT
  2. name – The type will be TEXT
  3. date – The type will be DATETIME
  4. website – The type will be TEXT
  5. entry – The type will be TEXT

I suggest using phpmyadmin to setup this table in the database, if you don’t feel up to creating this table you can download this file guestbookentries.sql

You can import that file using phpmyadmin and it will create the table for you.

Once the table has been created you need to create a new file and name it sqlcon.php and place the following code into this file.



//This line of code connects to the mysql server

//This line of code selects the correct database
@mysql_select_db($database) or die (“Unable to select database”);


Upload this file to a new folder on your server, create a folder called guestbook on your servers root and upload the sqlcon.php file to there.

You can point your browser to this file http://yourservername.com/guestbook/sqlcon.php

If the page comes up blank then everything is working as it should, if it comes up with an error then you’ve made a mistake somewhere. I’d be happy to help troubleshoot any problems you are having up to this point.

This concludes Part 2 of the tutorial

Just thought I would share some of my php knowledge with the rest of the world and cover a much asked about topic with a simple step by step tutorial.

This tutorial will be divided into parts starting with how to check and ensure that your server meets the minimum requirements to host a guestbook.

To start with you should make sure that you have a host that supports php as well as mysql.

Here’s a quick way you can check if your server supports php and mysql

Create a new file and call it phpinfo.php and place the following code in it.


Upload this file to your servers root folder and point your browser to it, so for example if I uploaded this file into my servers root folder I would point my browser to the following.


First, if your server supports php, then it will run this file and output information related to your php configuration, search for mysql on this page, if its there then the server supports it. 

This concludes Part 1 of the tutorial.