PHP Code Snippet Library
Available Snippets
+ Affichage

+ PHP_CSL_6

 + Snips_Add

 + Cats_Edit

 + Menu

 + Cats_Delete

 + Middle

 + Cats_Add

 + Snips_Delete

 + README

 + Index

 + Snips_Edit

 + Configuration

 + Classes

+ String_manipulation

+ Variables

Generic Options
+   Main page

+   Add new snippet

+   Add new category

+   Edit a category

+   Delete a category

Unique Options
+   Edit this snippet

+   Delete this snippet

+   Edit this category

+   Delete this category

Syntax for: PHP_CSL_6 . Cats_Delete
<?
if(isset($_POST['cats_delete']) || isset($_GET['cats_delete'])) {
    
// double check that the user wishes to delete the selected category.
    
if(!isset($_POST['confirm'])) {
        if(!isset(
$_POST['cats'])) {
            
$cats $_GET['cats_delete'];
        } else {
            
$cats $_POST['cats'];
        }
        echo 
'</br><form action='.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' method=post>';
        echo 
'<table align=center class=table1 cellpadding=6><tr class=rowpic><td>Delete a category</td></tr><tr align=center><td>';
        echo 
'<font color=red>Are you sure you want to delete \' '.$cats.' \' ?</font></td></tr><tr align=center><td>';
        echo 
'<input type=hidden name=confirm value=yes>';
        echo 
'<input type=hidden name=cats value='.$cats.'>';
        echo 
'<input type=button class=submit name=cancel OnClick="document.location=\''.$_SERVER['HTTP_REFERER'].'\'" value=NO>&nbsp;&nbsp;';
        echo 
'<input type=submit class=submit name=cats_delete value=Yes>';
        echo 
'</td></tr></table></form>';
    } else {
        
// has the user has confirmed the deletion ??
        
if($_POST['confirm'] == "yes") {
            if(
cats_delete($_POST['cats'])) {
                echo 
'</br><div align=center><b>Category Deleted !!</b></br>';
                echo 
'<a href=index.php>click here to refresh and see changes.</a></br></div>';
                echo 
'<script language=javascript>
                alert("Category Deleted");
                document.location="index.php";
                </script>'
;
            } else {
                echo 
'some type of error happend.</br>';
            }
        }
    }
    
    
} else {

echo 
'</br><form action='.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' method=post>';
echo 
'<table align=center class=table1 cellpadding=6><tr class=rowpic><td colspan=2>Delete a category</td></tr><tr><td>';
echo 
'Select category: </td><td align=right><select name="cats">';
$all_cats cats_get();
foreach(
$all_cats as $cat) { 
    if(
strlen($cat) >1) {
        echo 
"<option value=$cat>$cat</option>\n";
    }
}
echo 
'</select></td></tr><tr align=center><td colspan=2>';
echo 
'<input type=submit class=submit name=cats_delete value=submit>';
echo 
'</td></tr></table></form>';

}
?>
 
Description for: PHP_CSL_6 . Cats_Delete
Delete a Category.