Creating a simple PHP guestbook

Creating simple PHP guestbook.


In this tutorial, we have to create 3 files.
1. guestbook.php
2. addguestbook.php
3. viewguestbook.php

1. Create table name "guestbook" in database "test".
2. Create file guestbook.php.
3. Create file addguestbook. php.
4. Create file viewguestbook.php

STEP1: Set up database

CREATE TABLE `guestbook` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`comment` longtext NOT NULL,
`datetime` varchar(65) NOT NULL default '',

If you don't know how to create database and table, read this tutorial

STEP2: Create file guestbook.php

############### Code

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<td><strong>Test Sign Guestbook </strong></td>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<form id="form1" name="form1" method="post" action="addguestbook.php">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><input name="name" type="text" id="name" size="40" /></td>
<td><input name="email" type="text" id="email" size="40" /></td>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<td><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td>

STEP3: Create file addguestbook.php

############### Code

// Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="guestbook"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");

$datetime=date("y-m-d h:i:s"); //date time

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";

//check if query successful
echo "Successful";
echo "<BR>";

// link to view guestbook page
echo "<a href='viewguestbook.php'>View guestbook</a>";

else {
echo "ERROR";


PAGE 1 | 2 |

Similar Post

PHP Limit upload file size

This upload form can limit file size.

Form Validation Using Dreamweaver

In this tutorial shows you how to validate form using Macromedia Dreamweaver, it will show alert box when someone press submit button and forgot to fill your requied fields.