HomePHP Page 3 - Creating an Administration Area for a Simple Threaded Discussion Forum
The delall() and deltopic($uid) functions - PHP
Discussion forums usually need an administrator to handle various tasks that you wouldn't want just any forum user doing, such as banning other users. This article, the second of two parts, will show you how to set up an administration area for a threaded discussion forum, and some of the functions you might want an administrator to manage.
The delall() function is pretty straightforward. It deletes all the records in the table.
function delall(){ forumdb(); $query="Delete * from test"; $result=mysql_query($query); if(!$result){ echo 'Could not delete records because ' .mysql_error() . ''; }else{ echo 'All records have been delete'; } }
The deltopic($uid) function takes the uid of the record and uses that ID to delete it.
function deltopic($uid){ forumdb(); if(is_numeric($uid)){ $dbname="forum"; $host="localhost"; $dbh=mysql_connect($host) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($dbname) or die('I cannot select the database because: ' . mysql_error()); $query="Delete from test where uid=$uid Limit 1"; $r=mysql_query($query); if(mysql_affected_rows()==1){ echo "Record number <b>$uid</b> deleted"; }else{ echo "Could not delete record number <b>$uid</b> because " .mysql_error() . ""; } } }
In this function I've played it save and added the "Limit 1" statement to the delete query. This ensures that only one record is deleted and not all of them.