logicopinion Posted October 10, 2007 Share Posted October 10, 2007 Hello, with the code below i delete 1 row even if several rows are selected, what should i do to be able to delete as much rows as much i select at once. <?php mysql_connect("localhost", "root", "") or die ("Could not connect"); mysql_select_db("db1") or die ("Could not connect to DB"); if ($_POST['delete']) { $deleteID = $_POST['delete']; mysql_query("DELETE FROM dbtable WHERE id='$deleteID'") or die(mysql_error()); echo "The Row Number $deleteID has been Successfully Removed"; } else { echo "please select at least one row, to delete it"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72597-delete-multiple-rows-phpmysql/ Share on other sites More sharing options...
trq Posted October 10, 2007 Share Posted October 10, 2007 Firstly, you would need to make your form use arrays, then you simply implode on that array to form your query. eg; <form method="post"> <input type="checkbox" name="del[]" value="1"> <input type="checkbox" name="del[]" value="2"> <input type="checkbox" name="del[]" value="3"> <input type="submit" name="submit"> </form> <?php if (isset($_POST['submit'])) { $sql = "DELETE FROM dbtable WHERE id IN('" . implode("','",$_POST['del']) . "');"; if (mysql_query($sql)) { echo "The Rows Number " . implode(" ",$_POST['del']) . " where Successfully Removed"; } else { echo "please select at least one row, to delete it"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72597-delete-multiple-rows-phpmysql/#findComment-366097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.