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_Edit
<?
if(isset($_POST['cats_edit'])) {
    
// double check that the user wishes to edit the selected category.
    
if(!isset($_POST['confirm'])) {
        
$cats $_POST['cats'];
        
$new_cat $_POST['new_cat'];
        
        
$reg = new regex;
        
$reg->set_string($new_cat);
        
$new_cat $reg->get_string();
        
        echo 
'</br><form action='.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' method=post>';
        echo 
'<table align=center class=table1 cellpadding=6><tr class=rowpic><td>Edit a category</td></tr><tr align=center><td>';
        echo 
'<font color=red>Are you sure you want to rename \' '.$cats.' \' to \' '.$new_cat.' \'?</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=hidden name=new_cat value='.$new_cat.'>';
        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_edit value=Yes>';
        echo 
'</td></tr></table></form>';
    } else {
        
// has the user has confirmed the ammendment ??
        
if($_POST['confirm'] == "yes") {
            if(
cats_edit($_POST['cats'], $_POST['new_cat'])) {
                echo 
'</br><div align=center><b>Category Edited !!</b></br>';
                echo 
'<a href=index.php>click here to refresh and see changes.</a></br></div>';
                echo 
'<script language=javascript>
                alert("Category Edited");
                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>Edit 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";
            if(isset(
$_GET['cats'])) {
                if(
$_GET['cats'] == $cat) {
                    echo 
" selected ";
                }
            }
        echo 
">$cat</option>\n";
    }
}
echo 
'</select></td></tr><tr><td>';
echo 
'Enter new title:</td><td><input type=text maxlength=20 size=20 name=new_cat></td></tr>';
echo 
'<tr align=center><td colspan=2>';
echo 
'<input type=button class=submit name=cancel OnClick="document.location=\'index.php\'" value=Cancel>&nbsp;&nbsp;';
echo 
'<input type=submit class=submit name=cats_edit value=Add>';
echo 
'</td></tr></table></form>';

}
?>
 
Description for: PHP_CSL_6 . Cats_Edit
Edit a Category.