Linking and working principle of comment script

Here is the part 1 of comment posting 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

//////// start of comment /////////////
$p_name="1be"; // Unique file name of the page.
require "config.php"; //Remove if already have db connection
require "cmt-display.php"; // To display the comments
require "cmt-formck.php"; // Processing the form data
require "cmt-form.php"; // To display the form.
/////// end of comment //////////////
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.

$q=mysql_query("select name, dtl,dt from cmt_post where p_name='$p_name' and status='apv' order by dt ");

echo "<table width='400' border='0' cellspacing='1' cellpadding='0'>";
while($nt=mysql_fetch_array($q)){ $dtl=nl2br($nt['dtl']);
echo "<tr bgcolor='#f1f1f1'><td>$nt[name]</td><td align=right>".date("d-m-Y",strtotime($nt['dt']))."</td></tr>";
echo "<tr ><td colspan=2>$dtl</td></tr>";

}
echo "</table>";

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.

admin area works in this comment posting script.

How to install the script in part 3



Download the full script here


plus2net.com




tashi

25-05-2009

So happy to know such helpful website Plus2net.com

Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer