In this tutorial series, we are going to create a website at PHPandMySQL.inmotiontesting.com. This website is going to have 2 pages, and each page is going to allow for comments.

When users submit a comment, we'll want to keep track of the following information:

  • Their name
  • Their email address
  • Their website
  • Their actual comment
  • The time the comment was submitted

In order to keep track of this data, we need to:

  1. Create a database for our website
  2. Create a table in the database that has values for name, email, website, and comment.

Step 1. Creating a Database

The easiest way to create a database is to use the MySQL Database Wizard available in cPanel. This will not only create a database for you, but help you create a database user and assign the user privileges to your database. For more help with creating a database, please see How do I create a MySQL Database in my cPanel?

If you're following along with our example, we've used the MySQL Database Wizard and:

  1. Created a database named inmoti6_mysite
  2. Created a database user inmoti6_myuser with a password of mypassword
  3. Assigned inmoti6_myuser with privileges to inmoti6_mysite

create-a-database-using-wizard

Step 2. Creating a Table

Now that we've created our database, we need to create a table to hold all user comments. This table will be called "comments". To create this table:

  1. Log into cPanel and click the phpMyAdmin icon
  2. Select your database in the left menu. (we clicked on "_mysite" because our database is "inmoti6_mysite")
  3. On the right side of the page under "Create new table on database", enter "comments" as the name and 7 as the number of fields and click "Go"
    create-a-new-table-for-user-comments
  4. On the next screen, we will need to fill in specific details for our table. Please use the screenshot and details below to create the table

    Field: id
    Type: INT
    A_I: (put a check in the box)
    To help manage individual comments, for example to delete one, we want to assign a specific id number to each comment.

    Field: name
    Type: VARCHAR
    Length/Values: 60

    Field: email
    Type: VARCHAR
    Length/Values: 60

    Field: website
    Type: VARCHAR
    Length/Values: 60

    Field: comment
    Type: TEXT

    Field: timestamp
    Type: TIMESTAMP
    Default: CURRENT_TIMESTAMP

    Field: articleid
    Type: INT
    Each comment needs to belong to a specific article, otherwise we wouldn't know which comments to display for which pages.

    setting-specific-details-for-the-table

  5. After you have filled in the details above, click "Save"
    our-comments-table-has-been-successfully-created

Congratulations, as this point we have successfully created our database and setup our table! In our next article, we'll show you how to create a form using HTML that asks the user for their comment.

Continued Education in Course 205: Using PHP to create dynamic pages
You are viewing Section 2: Setting up a database to handle form data from a website
Section 1: How to create a custom PHP contact form with validation
Section 3: Creating a simple HTML Form to get user comments
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

2013-08-22 3:26 am
Hi Brad,
Thanks for the share, and actually I was really impressed with the way you made it look so simple with all those pics! I was just about to hire some web developers for this task and here your blog came to my rescue and saved me some bucks :).
n/a Points
2014-09-23 5:53 am

I doubt I can just set them as an admin and myself as a subscriber and be done with it,

Staff
10,345 Points
2014-09-23 9:16 am
Hello asiskumar,

Thank you for contacting us. Indeed there is most likely more to the setup. We are happy to help with any specific questions, or steps you are having problems with.

This guide is part of our full class on Using PHP to create dynamic pages.

If you have any further questions, feel free to post them below.

Thank you,
John-Paul

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

4 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!