Linking and working principle of comment script
We will try to keep it more modular so with little effort this script can be integrated or added at the end of many articles / content pages. You can read our content management script and this script can easily integrated with content management script.
At the end of every article or content the postings submitted by visitors will be displayed. This is done by collecting the postings of that particular page. Here every page is given one unique identification tag. Inside the main table the length of the field p_name is kept as 10 so our identification tag for the page should not be more than 10 char long. This identification tag we will use to collect all the postings stored in our main table. This code is kept inside one file and this file is included at every page. Here is the code used at the page level …
You can see in the above code first we have declared the unique identification name or tag of the page. This is stored in the variable $p_name. This value is used while collecting and posting records to the database. In the next line we include config.php file to get connection to database. If the database connection is already there then this line can be removed or commented. In the next line we include the page cmt-display.php. This page collects the comments posted by the visitors and display them. It uses the unique page name ( or tag ) and collects the records. Inside the where clause of sql query we have restricted the records which are not approved by the site admin. Here we will collect records for which status is set to apv( approved ) . Finally we will display them in the order of data field. While displaying we will convert the date filed value to readable format by using strtotime function. Here is the complete code for displaying the postings.
After displaying the postings we have included the file which takes care of form postings. Here the code inside the file is kept inside one if condition which checks the variable $todo. The value of the variable depends on whether the form is submitted or not. Inside this if block all the form validations are kept and error message is shown if validation is failed. You can add more validation if require. For easy understanding minimum validation is used. You can add validation preventing spammers posting URL or any other tags inside the message. Finally if all validations are passed then data is added to the table with status as ns , for admin to approve. Here along with each posting the unique page tag is stored.
Next task is to add the form. That is done by including the cmt-form.php page. The form is very simple. It only ask three inputs , name email and comment. It also uses one hidden tag todo to trigger the code inside cmt-formck.php once the form is submitted.
Download the full script here
Subscribe to our YouTube Channel here
This article is written by plus2net.com team. https://www.plus2net.com
| ▼ More on User Comment posting script