0

here is a code that would delete a page access from each user level but i have an error which is Notice: Undefined index: checkbox
here is the code

    <?php
    $userId = $_GET['id'];
    $sql = mysql_query("select * from cms_userlevels where user_level='$userId'");
    $row2 =  mysql_fetch_array($sql);
    echo "
    <center>
    <table class='left'>
        <form method='post' action='manageuserlevels.php?id=". $userId. "' onSubmit='return validate();'>
            <tr>
                <td id='TD4'>User Level ID </td>
                <td id='TD4'><input type='text' name='usertype' value='".$row2['user_type']."'></td>
            </tr>
                        <tr>
                <td id='TD4'>Delete </id>
                <td id='TD4'><input type='Checkbox' name='delete'></td>
            </tr>
            <tr>
            <td id='TD4' colspan='4'><center><input type='Submit' name='Update' value='Update'></td>
            </tr>
        </form>
        </form>
    </table>";
    ?>
    <table class="left">
    <tr>
    <td>Remove Access:</td></tr>
     <?php 
        $haslevel = mysql_query("select * from cms_userlevels, cms_level_page_matches, cms_pages
        WHERE cms_userlevels.user_level = '$userId'
        AND cms_level_page_matches.level_id = '$userId'
        AND cms_level_page_matches.page_id = cms_pages.id");
        $trylng = mysql_num_rows($haslevel);

        while($getlevel = mysql_fetch_array($haslevel)){
        $showhaslevel1 = $getlevel['page_id'];
        $showhaslevel2 = $getlevel['page_title'];
        echo"
        <tr><td>"; ?>
        <input name="checkbox[]" type="checkbox" id="checkbox[]" 
value="<?php echo $showhaslevel1; ?>"><?php echo $showhaslevel2; ?></td></tr>
<?php } ?>
if(isset($_POST['Update']))
    {
        $userId = $_GET['id'];
        for($i=0;$i<count($_POST['checkbox']);$i++){
            $del_id=$_POST['checkbox'][$i];
            echo $del_id;
                $deletelevel = mysql_query("DELETE FROM cms_level_page_matches where level_id='$userId' and page_id='$del_id' ");

                        header('location:manageuserlevels.php?id=". $userId. "');
        }
        if(isset($_POST['delete']))
            {
                $delete1= mysql_query("DELETE FROM cms_userlevels where user_level = '$userId'");
                header('location:manageuserlevel.php');
            }

                $update = mysql_query("UPDATE cms_userlevels set
                                                              user_type='$_POST[usertype]'
                                                              where
                                                              user_level='$userId' ");
    }
    ?>

heres the data base

cms_userlevels
user_level user_type
1          Admin
2          Student

user_pages
id         page name
1          page1.php
2          page2.php

user_level_page_matches
id        user_level page_id
1         1          1
2         2          2
2
Contributors
1
Reply
5
Views
3 Years
Discussion Span
Last Post by pritaeas
0

On line 45 you use $_POST['checkbox'], but this may not necessarily have a value. I assume if nothing is checked, then no updates are needed, so you can probably do this on line 42:

if (isset($_POST['Update']) && isset($_POST['checkbox']))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.