Page 1 of 1

delete with checkboxes ??

Posted: Fri Aug 24, 2007 2:08 pm
by djdon11
HI friends ..

i have a show page which shows all the records of the users with edit delete option with each ..

now i want to add check boxes with each record & want to give user choice to delte more than 1 record with the selection of check boxes ....
means if user select with check of the checkboxes then only those records should be deleted ...

can anybody gives me any idea for this stuff ????

Posted: Fri Aug 24, 2007 3:02 pm
by Begby

Code: Select all

<input type="checkbox" name="ids[]" value="10" /> Record with ID of 10 <br />
<input type="checkbox" name="ids[]" value="28" /> Record with ID of 28 <br />
<input type="checkbox" name="ids[]" value="32" /> Record with ID of 32 <br />

Code: Select all

// ... validate your $_POST somewhere before this

$ids = $_POST['ids'] ;
$keysToDelete = implode(',', $ids) ;

$sql = "DELETE FROM table WHERE idField IN ({$keysToDelete})" ;

simple validations

Posted: Sun Aug 26, 2007 10:16 am
by yacahuma
just make sure there are integers, never trust user input data

Code: Select all

$ids = array();
foreach($_POST['ids] as $v)
  $ids[] = intval($v);
$keysToDelete = implode(',', $ids) ;