PEAR Articles

  Home arrow PEAR Articles arrow PEAR CMS: Index and Delete Scripts
PEAR ARTICLES

PEAR CMS: Index and Delete Scripts
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-11-26

    Table of Contents:
  • PEAR CMS: Index and Delete Scripts
  • Delete Script continued
  • The index.php script
  • The code explained

  •  
     

    SEARCH CODEWALKERS

    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=’’;

    More PEAR Articles Articles
    More By David Web

    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning

    Developer Shed Affiliates

     



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