PEAR CMS: Index and Delete Scripts
(Page 1 of 4 )
This article will look at the index and delete scripts. The index page for the admin section is the first page that you will see when entering the admin portion of the site. It displays a welcome note. There are also a lot more links on the navigation panel of the admin section. This is the eleventh part of a twelve-part series on building a content management system with PEAR, so without any further ado, let’s take a look at the delete script.
The Delete script
The delete script is used to get rid of any data that you don’t want in the CMS. It removes articles and authors as needed. It has the following code:
<?php
//set error variables
$err=false;
//check if author id has been sent
if(isset($_GET['aid'])){
//check if it is numeric
if(is_numeric($_GET['aid'])){
//first delete author
$sql="DELETE FROM authors WHERE aid=$_GET['aid']";
$delauth = $db->query($sql);
if(!$delauth){
$err=true
}
}
//Then delete all articles written by author
$sql="DELETE * FROM stories WHERE author=$_GET['aid']";
$delarts= $db->query($sql);
if(!$delarts){
$err=true
}
}
if(!$err){
//get back to the list authors page
header(location:"listauth.php");
}
}else{
echo The following error(s) occurred:<br>
echo $errmsg.”<br>”;
}
?>
The delete script starts by declaring some Boolean variables that we will use to detect errors in the execution of the code. The variables are $errmsg and $err. The $err variable is of type Boolean; it can only have one of two values: TRUE or FALSE.
The $errmsg variable is of type string and will contain different types of messages based on where in the code it is. We set it to false at the beginning, because it has not been used yet. This script is called by the listauth.php script which sends an article ID to the delete script when a user clicks on the delete link.
<?php
//set error variables
$err=false;
$errmsg=’’;
Next: Delete Script continued >>
More PEAR Articles Articles
More By David Web