Create a GuestBook with PHP

After a lot of posts, I realised that there is not one tech post in my blog. So here comes the first tech post.

Creating a guest book is very simple in PHP. After playing around with PHP for sometime I wonder how easy it is for creating dynamic web applications. I have heard of a few drawbacks of PHP but for what I intend to use it, I have no problems. Below is a detailed description of the guest book application

Database

If you do not have MySQL installed, download and install from http://dev.mysql.com/downloads/mysql/5.0.html. Once this is done, the database has to be setup to hold info from the guestbook form (which will be created shortly)

First, a database has to be created. Let the database be called guestdb. Use the following SQL statement to create the database. Login to MySQL. If you are running MySQL server on your desktop, your root password will not be set. You need a provide a password while logging in as root. Change the root password

mysqladmin -u root password <password>

Login as root and create a new database

create database guestdb;

Create a new user name for use with your guestbook.

grant all privileges on guestdb.* to guest@”%” identified by ‘guest’

The above statement tells MySQL to create a new user name called guest and with the password as guest. The user will have access to all the tables in guestdb. The user will be able to connect from any computer (host)

A table is required to hold the information that users leave on the guestbook. Let the table be guestbook. The SQL to create the table is

create table guestbook (ID INT NOT NULL AUTO_INCREMENT, Name VARCHAR(50),Email VARCHAR(100), Comment TEXT NOT NULL, Date DATETIME NOT NULL,PRIMARY KEY(ID));

Coding

A HTML form is required to capture info from the user. The form will be called gb.html

Once the form is submitted, the data should be captured and entered into the guestbook table. This is accomplished by gbprocess.php

To view the GuestBook, viewgb.php will be used


Happy Coding! Reuse of code permitted

 


Advertisements

15 responses to “Create a GuestBook with PHP

  1. Dear Bala,

    Frist at all thankyou for your Create a GuestBook with PHP, l have facing some problem on it, becuase l am a newbies for this, l have create a database call guestdb, also MySQL 4 to create a new user name called guest and with the password as guest. but after that it come out error message” Table ‘guestdb.guestbook’ doesn’t exist. “What happen to it?

    Question,
    DO l need to upload the file gb.html, gbprocess.php, viewgb.php to my db folder in the server(It was ask to do that from the webhost company. l have upload it into both db (databse folder) & wwwroot (public access files) folder. But still getting the error message.

    Can l change the english wording into chinese wording like name, email, etc.

    thanks
    regards
    fooksam

  2. Hi Fooksam,

    What you have created is database. You need to create a table in the database to hold the information submitted by the users. Please use the create table statement above to create a table. You can have any number of tables in your database. You can have one table for your guest book, another for your To Do list and yet another for your Party Registration application. You can also create multiple databases provided your web hosting company allows you to do so.

    You can read http://en.wikipedia.org/wiki/Database for more information.

    Also, you need not upload the gb.html, gbprocess.php and viewgb.php files to the db folder. Hope I am clear.

    Thanks,
    Bala

  3. I missed out the language part of your question. I think you should be safely able to change the names into Chinese. But you might need some advanced options to store those Chinese characters in the database. I am sorry I could not help you on that.

    Thanks
    Bala

  4. Hi am having some trouble… Your tutorial is very understanding… Thank you…
    But i am having trouble adding and view the comments still… Do you have to create an actual database from Microsoft access or something? or does the MySOL Command Line Client do that itself? Coz ive done that and still nothing… :-s

    Thanx
    Tara

    • Tara, Thanks for your comment. We create a database with MySQL. MySQL is a database server which can have several databases unlike Microsoft Access which is file based. Can you provide more details about what problems you face, so that I can help?

      • “; echo “”; echo “”; echo “”; echo “”; echo “”; } //Close the connection mysql_close($connection); ?>
        Name Email Comment Date
        $row[1] $row[2] $row[3] $row[4]

  5. Thanks for getting back to me. Well when i try testing it at home, the data I input in the comments fields are not shown on the process or view page to see the comments and when I go to view other comments, it shows…

    “; echo “”; echo “”; echo “”; echo “”; echo “”; }
    Name Email Comment Date
    $row[1] $row[2] $row[3] $row[4]

    How can I resolve this?
    Thanx

    • @Tara, Looks like the PHP file is not processed by a web server. What operating system and web server are you running? Have you installed PHP? Does your web server support PHP?

      • Hi Bala,

        Well no i don’t have a web server installed at this moment of time, I have PHP installed and I am currently running Windows XP proffesional.
        If you could suggest a good web server I can install would be great. The purpose of my website is for it to run of my laptop for a small project I have. If I tranfers my work to another computer would it still work or would I have to create another database from that computer? I mean that once I have completed my project I will be hosting my website on a proper web sever and not my laptop.

        Thank You
        Tara

        • Hi Tara,

          If you do not have a web server, then where do you put the PHP files to execute? Am I missing something here?

          On the other question you had asked, yes, you need to create the Database on the other computer where you intend to run your website.

          ~Bala

  6. Sorry i meant don’t have that installed either… i have tried but I need a web server first… Any recommendations??

    ~T~

    • Tara, I would recommend the Apache HTTP server and PHP. Also, since you seem to be a beginner, try to get a good book on programming PHP or find some on the internet.

  7. PAKp46 Thank you for the material. Do you mind if I posted it in her blog, of course, with reference to your site?

  8. Genuinely when someone doesn’t be aware of then its up to
    other visitors that they will help, so here it takes place.

  9. It really is mostly extremely difficult to find well-aware personal on this spot, but you encounter as like you fully understand what exactly you’re preaching about! Take care

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s