Click here to Skip to main content
15,902,832 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI i am try to delete multiple data by using check-box in php
i tried but is don't works not getting the ids from the check-box..
my code is

<pre lang="xml"><tbody>
<?php while ($row = mysql_fetch_array($res)) { ?>
        <tr class=" <?php echo $class = ($class == 'even') ? 'odd' : 'even'; ?>"  >
            <td><input type="checkbox" name="checkbox[]" value="<?php echo $row['grievance_id']; ?>"/></td>
            <td><?php echo $row['grievance_id']; ?></td>
            <td><?php echo $row['grievance_reason']; ?></td>
            <td align="center"><?php echo $row['grievance_meeting']; ?></td>
            <td align="center"><?php echo $row['next_review']; ?></td>
            <td align="center"><?php if($row['matter_resolved'] == 1)
                                    {  echo "Yes";  }else{  echo "No";  } ?>
            </td>
        </tr>
<?php } } ?>
    </tbody>
</table>
</form>
<?php
if(isset($_POST['action']) == "gdelete")
{
        $checkbox = isset($_REQUEST['checkbox']);
        $countaa = count($checkbox);
    for($i=0;$i<$countaa;$i++){
        echo $del_id  = $checkbox[$i];
        echo $sql = "DELETE FROM hs_hr_emp_grievances WHERE grievance_id=$del_id";
        $result = mysql_query($sql);
    }
}
?

>
Posted

1 solution

PHP
$checkbox = isset($_REQUEST['checkbox']);
$countaa = count($checkbox);


You have set $checkbox to the boolean value returned by isset(), so count($checkbox) and $checkbox[$i] make no sense. You probably meant to set it to $_REQUEST['checkbox'].

Also, watch out for SQL injection - don't put $del_id in your query without escaping it first.
 
Share this answer
 
Comments
vicky87 6-Apr-11 7:32am    
i am having error Undefined index: checkbox with this $_REQUEST['checkbox'] so thats why i use isset()...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900