Creating an Administration Area for a Simple Threaded Discussion Forum - The delall() and deltopic($uid) functions
(Page 3 of 4 )
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.
Next: Database connection, bad words >>
More PHP Articles
More By Jacques Noah