Making and viewing thread comments
In this section, we'll go over how to allow a registered user to make a comment and how to display comments for a forum thread.
The code for this version will be written in a procedural method.
Refer to the Get Started section to know what you need to use this tutorial. You must also have an understanding of HTML and how a web page is constructed.
To use this tutorial, we recommend that you use our other lessons, User registration, User log-in and log-out, Setting restrictions with PHP, Posting a forum thread, Viewing a thread and PHP forum - The database to be able to duplicate what we have.
The database described in those tutorials is necessary if you plan to follow this tutorial line-by-line. Only logged-in users will be able to post to this forum.
In the previous lessons, User registration and User log-in and log-out, we created and worked with a database and table. We'll be using that same setup with modifications. We're adding the fields "fname," "lname" and "phone."
Database name: social
We'll use this database for more social apps
|commentID||INT (11)||This will be the primary key. It is a unique ID number assigned to each individual comment. It should be set to increment automatically.|
|threadID||INT (11)||The identification number of the thread each comment belongs to.|
|userID||INT (11)||The identification number of the user who created the comment.|
|content||LONGTEXT||The string of text the user entered as their comment.|
|created||INT (11)||The numberic value of the time a comment was created|
|isDeleted||Bool||A TRUE/FALSE value that will control whether or not the comment can be viewed.|
|timestamp||Timestamp||A time stamp, provided by the database, about time the comment was last updated.|
Every comment will be held in this table for all of the boards.
Displaying the thread
Refer to the lesson about Viewing a thread to display the contents of a single forum thread.
Displaying the comments
This general template will fit the information we want to display to a user on each individual thread. Let's query the database for the information about the thread's comments. This can only be done if the ID of a thread is in the URL as a
$_GET variable. For this lesson, only logged-in users can view forum threads. If they are, query the database for the thread.
Posting a comment
Questions or problems? Want to contribute to this tutorial or others?