delete with checkboxes ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
djdon11
Forum Commoner
Posts: 90
Joined: Wed Jun 20, 2007 5:03 pm

delete with checkboxes ??

Post 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 ????
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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})" ;
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

simple validations

Post 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) ;
Post Reply