Home arrow PHP arrow 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.

TABLE OF CONTENTS:
  1. Creating an Administration Area for a Simple Threaded Discussion Forum
  2. Code
  3. The delall() and deltopic($uid) functions
  4. Database connection, bad words
By: Jacques Noah
Rating: starstarstarstarstar / 6
October 23, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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.



 
 
>>> More PHP Articles          >>> More By Jacques Noah
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap

Dev Shed Tutorial Topics: