In this tutorial, I will guide you through the process of setting up a simple HTML form for user comments.
We will be working with a MySQL Database using PHP on cPanel, creating a simple two-page website where users can post comments on either page and view all posted comments.
Let’s get started.
A Quick Introduction to HTML Forms
Using HTML forms, users of your website can input different data into your website. This data will be submitted to another page for processing. An HTML form can collect a user’s comment or information, and add the submitted comments to your database for review.
Gathering the Form Data
HTML forms can handle various types of input. For example:
- Text boxes
- Radio buttons
- Check boxes etc.
Submitting the Form Data
When the user completes filling the required data in the HTML form and clicks the submit button included in the form, their data is sent for processing. The submitted data can be processed on that same page or sent to a different script to add to your database.
The data is transmitted using either the GET or POST method. With GET, the data is appended to the URL, like so:
GET domain.com/page.php?name=Daniel&[email protected]
Here, the name and email are visible in the URL. Conversely, with POST, the URL remains clean:
POST domain.com/page.php
…and the name and email are sent behind the scenes.
Our Example Contact Form
For our comments form, we’ll primarily use text boxes for input. Below is an example of what our contact form will look like: