| |
|
Site admin approval of comments posted by visitors script |
You can read the main tutorial on posting comment here. We will discuss how the admin are works in posting comment script. The main purpose of admin area is to approve or delete the postings of the visitors. By default once the comments are posted the status of the posting remains at ns ( not seen ). Records with status equal to ns are not displayed in public area. Inside the admin area site admin after login can view the all the comments or only list the comments which are in ns status ( not seen ). While viewing the list site admin can see name, email date of post etc along with status of the posting. Admin can click the link Details and see full details of the post. Here admin can change the status to apv ( approved ) or can delete the post. Here any approved posting ( status = apv) can be changed to not seen ( status = ns ).
In list.php page all the records ( or posts ) get listed in the order of date of post. If required admin can go to a page where not approved ( status =ns) records are only displayed. Here is the code for list.php page, a simple collection of records from the table.
@$msg=$_GET[''msg''];
if(isset($msg) and strlen($msg) >1 ){
echo "<span style=''background-color: #FFFF00''>$msg</span>";
}
//////////////////////////////////////////////////
$q=mysql_query("select * from cmt_post order by dt ");
echo "<table width=''100%'' border=''0'' cellspacing=''1'' cellpadding=''0''>";
while($nt=mysql_fetch_array($q)){
echo "<tr bgcolor=''#f1f1f1''><td><b>id</b>:$nt[post_id] <b>name</b>:$nt[name] <b>email</b>:$nt[email] <b>status</b>:$nt[status] <a href=''list-dtl.php?post_id=$nt[post_id]&f_name=list.php''>Details</a></td><td align=right>".date("d-m-Y",strtotime($nt[''dt'']))."</td></tr>";
echo "<tr ><td colspan=2>$nt[dtl]</td></tr>";
}
echo "</table>";
///////////////////////////////////////////////
Admin can view the full details with status change option by clicking the detail link available with each posting. On clicking that admin can visit the page list-dtl.php page where posting details with option to change the status will be displayed. Here is the code.
////////////////////////////////////////////////////////////////////////////////////////////
$post_id=$_GET[''post_id''];
$f_name=$_GET[''f_name''];
$q=mysql_query("select * from cmt_post where post_id=$post_id ");
echo mysql_error();
$row=mysql_fetch_object($q);
echo "<table width=''100%'' border=''0'' cellspacing=''1'' cellpadding=''0''>";
echo "<tr bgcolor=''#f1f1f1''><td><b>id</b>:$row->post_id <b>name</b>:$row->name <b>email</b>:$row->email <b>status</b>:$row->status</td><td align=right>".date("d-m-Y",strtotime($row->dt))."</td></tr>";
echo "<tr ><td colspan=2>$row->dtl</td></tr>";
echo "</table>";
echo "<hr>";
//////////////////////////////////////////////////////////////////////////////////////////////
//////////// Updation starts ////////////////////
switch($row->status)
{
case "ns":
$nsck="checked";
$apvck="";
break;
case "apv":
$apvck="checked";
$nsck="";
break;
default:
$apvck="";
$nsck="";
break;
}
echo "<form method=post action=''list-dtlck.php''><input type=hidden name=''todo'' value=''status-up''><input type=hidden name=f_name value=''$f_name''>
<input type=hidden name=post_id value=$post_id>
<input type=radio name=status value=''ns'' $nsck>Not Seen <input type=radio name=status value=''apv'' $apvck>Approved
<input type=radio name=status value=''del'' >Delete
<input type=submit value=''Update''>
</form>
";
///////////Updation ends ////////////////////////
Once the admin submit the form for change of status the form data goes to list-dtlck.php page. Here all the form data collected and first checked if delete options is selected. Record is deleted if delete option is given or the status is changed as per the selection. After the changes the page automatically redirect to list.php page with a message displayed at the top of the list.php page. Here is the code.
@$todo=$_POST[''todo''];
if($todo=="status-up"){
$f_name=$_POST[''f_name''];
$post_id=$_POST[''post_id''];
$status=$_POST[''status''];
if($status=="del"){
$q=mysql_query("delete from cmt_post where post_id=$post_id");
if(mysql_affected_rows() <> 1){
header ("Location: $f_name?msg=<br>Not able to delete Record ");
}else{header ("Location: $f_name?msg=<br>Record deleted "); }
}else{
$q=mysql_query("update cmt_post set status=''$status'' where post_id=$post_id ");
echo mysql_error();
if(mysql_affected_rows() <> 1){
header ("Location: $f_name?msg=<br>Not able to update Record ");
}else{header ("Location: $f_name?msg=<br>Record updated "); }
}// end of if else
}// end of todo checking
else{
header ("Location: $f_name?msg=<br>Data Problem");
}
With this let us learn How to install the script in part 3
Download the full script here
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
|
|