 |
Building a Comments Script by: bs0d |
Page: 1 of 4 (View All) |
Building a Comments Script
Introduction
This tutorial will guide you through the process of building a comments script with PHP.
The comments script will use a mySQL database to store and retrieve information. Its not
too advanced, but additional features can easily be added, such as a delete feature and
implementing usernames. If a user is logged in, display their username- if not, display
"Guest" or something along those lines. Well discuss that more in detail later. So lets
get started.
What you need
In order to build and use this script, you will need hosting that supports PHP, because
thats the language we are using to build it with. And access to a mySQL database, because
this is the type of database we are using to store and retrieve the comments data. I would
recommend using the newest versions of PHP, because I do know some things have changed, like
I will use $_POST instead of $_HTTP_POST_VARS, which $_POST the newer (and easier) method.
What to Expect
With this particular script, you can simply include the comments file on every page that
you would like comments to be made. Like this site, comments can be made on every page
of every article, as well as for every code sample. A person can enter their username,
subject of comment, form of contact (email or website) and finally, their comment. When
they submit the comment, the page will be refreshed and display their comment. First, will
appear the lists of comments for that page. And below that, will be a form to add a comment.
The Setup
The first thing you should do, is build a comments table in your database. You can name
the table anything you want. We'll use simply, "comments" for this tutorial. The comments
table will have 9 columns: article_id, page, date, time, username, ip, contact, subject,
and comment.
- The article_id is the unique id of the particular article the comment is for. Comment results
will not depend on this, but we can use it later for statistical purposes.
- Page is the url of the article and page number which it appears.
- Date and time will be when the comment was made.
- Username will come from the form.
- IP will contain the posters ip for spam / flood control later on.
- And finally, contact, subject and comment will also come from whats entered on the form
below all comments.
Below is the SQL to create the comments table.
No Comments for this page.
|
 |
Tutorial Stats |
| 45,880 |
Views |
| 16 |
Total Comments |
| 4.5 |
Rating of 5 (2 Votes) |
|