logixxxx Posted April 15, 2007 Share Posted April 15, 2007 Hello, how can I use a checkbox to delete multiple items with how I did this php? <form action=""><?php db(); $result = mysql_query("SELECT timestamp, id, title FROM " . $mysql["db_prefix"] . "main ORDER BY id DESC"); while($row = mysql_fetch_array($result)) { $date = date("l F d Y",$row['timestamp']); $id = $row['id']; $title = strip_tags(stripslashes($row['title'])); if (strlen($title) >= 50) { $title = substr($title, 0, 50); $title = $title . "..."; } echo " <input type=\"checkbox\" name=\"check\" value=\"\"> <b>$date</b> - <a href=\"editform.php?id=" . $id . "\">" . $title . "</a><br />"; } mysql_close(); ?> </form> Link to comment https://forums.phpfreaks.com/topic/47066-how-can-i-get-a-checkbox-to-delete-a-item/ Share on other sites More sharing options...
Barand Posted April 15, 2007 Share Posted April 15, 2007 Give chkboxes the same name ending with "[]" eg del_id[] so they get sent as an array. Give each chkbox the value of the id to be deleted. <?php if (isset($_GET['del_id'])) { $ids = join ("','", $_GET['del_id']); $sql = "DELETE FROM mytable WHERE id IN ('$ids')"; echo $sql; } ?> <hr /> <form> <input type='checkbox' name='del_id[]' value='1'> item 1 <br /> <input type='checkbox' name='del_id[]' value='2'> item 2 <br /> <input type='checkbox' name='del_id[]' value='3'> item 3 <br /> <input type='submit' name='action' value='Delete selected'> </form> Link to comment https://forums.phpfreaks.com/topic/47066-how-can-i-get-a-checkbox-to-delete-a-item/#findComment-229587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.