manojhooda Posted April 10, 2009 Share Posted April 10, 2009 How to delete selected record with checkbox in php. please help me with example code. Link to comment https://forums.phpfreaks.com/topic/153470-how-to-delete-selected-record/ Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 Let's say you have a checkbox and it's value represents the ID number of a table in your database: <input type="checkbox" name="mycheck" value="24"> We can check if it has been ticked and if yes, use the value from it to delete a record: if ($_POST['mycheck']) { $checkval=$_POST['mycheck']; if (mysql_query("DELETE FROM table WHERE id=".$checkval." LIMIT 1")) { echo 'Deleted'; } else { echo 'Not deleted'; } } Link to comment https://forums.phpfreaks.com/topic/153470-how-to-delete-selected-record/#findComment-806328 Share on other sites More sharing options...
Stephen68 Posted April 10, 2009 Share Posted April 10, 2009 Not sure if would use checkbox for this kind of thing for the user could pick a few checkboxes if you where giving them multi choices. Maybe I would suggest a radio button maybe? just my 2 cents Link to comment https://forums.phpfreaks.com/topic/153470-how-to-delete-selected-record/#findComment-806331 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 I personally only use checkboxes for deleting multiple stuff, like emails/private messages. I'd use a hyperlink and $_GET to delete single records. As in <a href="?delete=24">delete</a> and then $id = $_GET['delete']; and proceed with deletion... Link to comment https://forums.phpfreaks.com/topic/153470-how-to-delete-selected-record/#findComment-806340 Share on other sites More sharing options...
Stephen68 Posted April 10, 2009 Share Posted April 10, 2009 ya that is the way I do it as well, I just thought he wanted to use some kind of checkbox for it Link to comment https://forums.phpfreaks.com/topic/153470-how-to-delete-selected-record/#findComment-806375 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Lol yeah, it doesn't really make sense to use a checkbox for one record though. Link to comment https://forums.phpfreaks.com/topic/153470-how-to-delete-selected-record/#findComment-806385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.