tags:

views:

242

answers:

2

I have written to check all and delete but when i click on delete form is submit but value of check box is not posted

my html code is following:

<?php
$sql="select * from tbl_comment order by id desc limit $start,$rec_per_page";
$result = $db->sql_query($sql);
?>
<br>
<form action="?page=<?=$_REQUEST['page']?>&op=delete" method="post" name="email">
    <table border=0 cellpadding=5 width="100%" cellspacing=0>
        <tr class="text1">
            <td colspan=3 class="darkBlue"><B>Comment List</B></td>
        </tr>
        <tr bgcolor="#CACBD2" class="text1">
            <td class="text1"><B>Name</B></td>
            <td class="text1"><B>Comment</B></td>
            <td class="text1"><strong>Action   </strong></td>
        </tr>
        <?php
        $r1=0;
        $class='white';
        while($rec=$db->sql_fetchrow($result))
        {
            $status = $rec['status'];
            if($status==1)
                $activelink = '<a href="index.php?page='.$page.'&comment_id='.$rec['id'].'&op=status&flag=disapprove&page_em='.$page_em.'" onclick="return confirm(\'Do you want to disapprove?\')">Disapprove</a>';
            else
                $activelink = '<a href="index.php?page='.$page.'&comment_id='.$rec['id'].'&op=status&flag=approve&page_em='.$page_em.'" onclick="return confirm(\'Do you want to Approve?\')">Approve</a>';
        ?>
        <tr class="<?= $class;?>">
            <td><?=$rec['fname'].$rec['lname']?></td>
            <td><?=$rec['comment']?></td>
            <td><!--<a href="index.php?page=<?=$page?>&comment_id=<?=$rec['id']?>&op=delete" onclick="return confirm('Do you want to Delete?')">[X]</a>--><input type="checkbox" name="chkdelete[]" id="chkdelete[]" value="<?=$rec['id']?>" /><?=$rec['id']?>&nbsp;|&nbsp;<?=$activelink?></td>
        </tr>
        <?php
        if($class=='white')
            $class='lightBlue';
        else
            $class='white'; 
        }

        for($pages = 1; $pages <= $total_pages; $pages++) 
        { 
            if ($pages == $page_em) 
            { 
                $nav .= "<strong  style='font-size:12px;' class='redbold'>".$pages."</strong>&nbsp;&nbsp;";
            } 
            else 
            { 
                $nav .= "<a href=\"?page_em=".$pages."&page=comments\">".$pages."</a>&nbsp;&nbsp;";
            }         
        }

        if ($total_pages > 1)
        {
            if (($page_em-1) > 0) {
                $prev= "<a href=\"?page_em=".($page_em-1)."&page=comments\">Previous</a>&nbsp;&nbsp;";
            } else {
                $prev= "Previous&nbsp;&nbsp;";
            }
            $content .= "&nbsp;&nbsp;";
            if (($page_em+1) <= $total_pages) {
                $next.= "<a href=\"?page_em=".($page_em+1)."&page=comments\">Next</a>";
            } else {
                $next= "Next";
            }
        }

        $NavigationButton=$prev.$nav.$next;
        if($total_rec==0){
            $NavigationButton="Record not found!";
        }
        ?>  
        <tR class="text1">
            <td ><?=$NavigationButton?></td>
            <td></td>
            <td align="left">
                <strong>
                    <input type="checkbox" name="All" id="All" value="yes"  onclick="javascript:checkall();"/> (Select All) |
                    <label>
                        <input type="submit" name="Submit" value="Delete Selected" onclick="return confirm('Do you want to Delete?')"/>
                    </label>
                </strong>
            </td>
        </tr>
    </table>
</form>
<?php
}

And function to delete is following:

function delete_email()
{

    print_r($ids = $_POST['chkdelete']);

    foreach($ids as $key=>$id)
    {
        echo "hi2"; die;
        global $db;
        //$email=$_GET['comment_id'];
        $sql="delete from tbl_comment where id='".$id."'";
        $db->sql_query($sql);
        echo "deleted comments".$id;
    }
    //$url="index.php?page=".$page;
    //header("Location:".$url);
}

any one plese help me

A: 

As far as I can tell, your checkbox's name states chkdelete[] whereas you refer to a POST variable chkdelete (without the []).

Pawel J. Wal
no i cant get through this also
rajanikant
that's fine, $_POST['chkdelete'] should be array because input name ends with '[]'.
parserr
yes plese help me i have spent lot time on this i have done this way earlier but in this i unable to get any fault
rajanikant
Does the print_r statement show anything at all in `$_POST['chkdelete']` variable?
Pawel J. Wal
A: 
<form action="?page=<?=$_REQUEST['page']?>&op=delete" ...

are you hitting right function with this form action? also, if you're doing some redirects on this url, your $_POST data will be lost (another request is made, without post data).

should not have anything to do with your problem, but it's worth noticing that you're assigning same DOM id ('chkdelete[]') to all checkboxes, while it should be uniqe.

parserr