In this tutorial series, we’re showing you how to interact with a MySQL Database using php. We’re creating a simple 2 page website that allows users to post comments on either page, and then shows all comments that have been posted. In our previous article we created a database and setup a table to hold those comments, and now in this article we’ll setup a HTML form that allows a user to enter comments.
A quick introduction to HTML Forms
Gathering the Form Data
An HTML form allows a user to type data into a website, and then it submits the data to another page for processing. For example, if you fill out a comment on a website and hit submit, everything that you typed in is submitted to a script on the server that writes your comment to a database.
HTML forms can handle quite a few different forms of input. For example, they can handle:
- Text Boxes:
- Radio Buttons
- … and more!
Submitting the Form Data
After the user has filled in the above data and clicks a submit button, it will send all of their data to another script for processing. It can either send the data back to the same page for processing, or it can send it to a completely different script to handle the processing.
When the data is passed to a script for processing, it can be passed using either GET or POST. When using GET, all the data is passed in the url, such as:
As you can see, my name and email address is passed in the URL. If you use POST (instead of get), the URL will simple read:
… and my name and email address will be passed behind the scenes.
Our Example Contact Form
Because our comments form is going to be relatively simple, we will be using text boxes for most of the input. Below is our contact form and what the contact form will look like: