PEAR Articles
  Home arrow PEAR Articles arrow Page 2 - PEAR CMS: Index and Delete Scripts
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PEAR CMS: Index and Delete Scripts - Delete Script continued


    (Page 2 of 4 )

    First, we check to see if an author_ID has been sent. Since the id will come from an untrusted source, we have to filter the ID to make sure that it is what we expect it to be; in other words, we expect a number and that is what we should get. To verify that the ID is a number, we use the tried and tested is_numeric() function. This function will evaluate to false if the id is anything but a number.


    //check if author id has been sent

    if(isset($_GET['aid'])){

    //check if it is numeric

    if(is_numeric($_GET['aid'])){

    If both tests are passed, then the code continues to run a delete query that will remove the author that matches the given author ID:

    //first delete author

    $sql="DELETE FROM authors WHERE aid=$_GET['aid']";

    $delauth = $db->query($sql);

    If the query is unsuccessful, the $err variable is set to TRUE. This value will be used later to determine certain actions that the code must take. A error message is also added so that the user can see exactly where the error took place:

    if(!$delauth){

    $err=true

    $errmsg=”Error occurred while trying to remove author”;

    }

    Another query is run, but this time it is to remove all the articles that are related to the just-deleted author. This query is actually very important, since the articles will be left in the database without any link to the authors table, which also means that we won't be able to delete them in the same way that the other articles can be deleted:

    //Then delete all articles written by author

    $sql="DELETE * FROM stories WHERE author=$_GET['aid']";

    $delarts= $db->query($sql);

    The result value of the query is checked to see whether or not the query was successful. If it was not successful, the $err variable will be set to TRUE. An appropriate error message will also be set at this point:

    if(!$delarts){

    $err=true;

    $errmsg.=”Error occurred while trying to remove articles related to author ID:”.$_GET[‘aid’].”<br>”;

    }

    If the author ID was not sent in as a number, then the $err value is set to TRUE and the appropriate error message was set.

    }else{

    $err=TRUE;

    $errmsg.=”Invalid ID format<br>”;

    }//end numeric

    If the author ID was empty or not sent, then a $errmsg is set and the $err is set to TRUE:

    }else{

    $err=TRUE;

    $errmsg.=”Author ID not found.”<br>”;

    }//end

    If there are no errors, then the user is taken back to the listauthors page which should then reflect the changes:

    if(!$err){

    //get back to the list authors page

    header(“location:listauth.php");

    If there were errors, they are printed out to the screen:

    }else{

    echo The following error(s) occurred:<br>

    echo $errmsg.”<br>”;

    }


    ?>


    That’s it for the delete script. Next we look at the index.php script.

    More PEAR Articles Articles
    More By David Web


     

    PEAR ARTICLES ARTICLES

    - 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
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT