richardw Posted March 26, 2007 Share Posted March 26, 2007 I see the code posted by desithugg and I may look to use that. But my code is as follows: <?PHP if($_POST['submit']) { foreach($_POST as $id) { // loop through checkboxes mysql_query("DELETE FROM sidewalks WHERE id='$id1'"); // table and record id } ?> <?php } else{ // display form ?> <form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <?php $db = mysql_connect("localhost", "Uname", "PWD") or die("Could not connect"); $provridb = mysql_select_db("dpw",$db); $sql = "SELECT * FROM sidewalks WHERE ward ='9' ORDER BY treet_1,street_nmbr ASC"; $result = mysql_query($sql); $num_results = mysql_num_rows($result); echo 'There are currently ', $num_results,' records for this ward', '<br><br>'; while ($row = mysql_fetch_assoc($result)) { echo $row["street_nmbr"], " ", $row["street"] ?><input type="checkbox" name="<?=$row["id"]?>" id="<?= $row["id"]?>" value="<?= $row["id"] ?>" /> <br> <?php } mysql_free_result($result); ?> Any suggestions as how to fix this code? Thanks Link to comment https://forums.phpfreaks.com/topic/44389-multiple-row-delete-what-do-you-see-wrong-with-this-solution/ Share on other sites More sharing options...
desithugg Posted March 26, 2007 Share Posted March 26, 2007 woops srry wrong forum Link to comment https://forums.phpfreaks.com/topic/44389-multiple-row-delete-what-do-you-see-wrong-with-this-solution/#findComment-215559 Share on other sites More sharing options...
desithugg Posted March 26, 2007 Share Posted March 26, 2007 <?PHP if($_POST['submit']) { foreach($_POST['delete_list'] as $id) { // loop through checkboxes mysql_query("DELETE FROM sidewalks WHERE id='$id1'"); // table and record id } ?> <?php } else{ // display form ?> <form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <?php $db = mysql_connect("localhost", "Uname", "PWD") or die("Could not connect"); $provridb = mysql_select_db("dpw",$db); $sql = "SELECT * FROM sidewalks WHERE ward ='9' ORDER BY treet_1,street_nmbr ASC"; $result = mysql_query($sql); $num_results = mysql_num_rows($result); echo 'There are currently ', $num_results,' records for this ward', '<br><br>'; while ($row = mysql_fetch_assoc($result)) { echo $row["street_nmbr"], " ", $row["street"] ?><input type="checkbox" name="delete_list[]" id="<?= $row["id"]?>" value="<?= $row["id"] ?>" /> <br> <?php } mysql_free_result($result); ?> name="delete_list[]" you need the [] to pass arrays through forms Link to comment https://forums.phpfreaks.com/topic/44389-multiple-row-delete-what-do-you-see-wrong-with-this-solution/#findComment-215561 Share on other sites More sharing options...
richardw Posted March 26, 2007 Author Share Posted March 26, 2007 Not sure why, but it still won't delete... What am I missing? I have been on this code for too many hours, so I may be missing the obvious. Thanks <?PHP if($_POST['submit']) { foreach($_POST['delete_list'] as $id1) { // loop through checkboxes mysql_query("DELETE FROM sidewalks WHERE id='$id1'"); // table and record id } ?> <?php } else { // display form ?> <form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <?php $db = mysql_connect("localhost", "Uname", "PWD") or die("Could not connect"); $provridb = mysql_select_db("dpw",$db); $sql = "SELECT * FROM sidewalks WHERE ward ='9' ORDER BY street_1,street_nmbr ASC"; $result = mysql_query($sql); $num_results = mysql_num_rows($result); echo 'There are currently ', $num_results,' records for this ward', '<br><br>'; while ($row = mysql_fetch_assoc($result)) { echo $row["street_nmbr"], " ", $row["street"] ?><input type="checkbox" name="delete_list[]" id="<?= $row["id"]?>" value="<?= $row["id"] ?>" /> <br> <?php } mysql_free_result($result); ?> <input type='submit' value='Delete Selected'> </form> <?php } // end if ?> Thanks again! Link to comment https://forums.phpfreaks.com/topic/44389-multiple-row-delete-what-do-you-see-wrong-with-this-solution/#findComment-215585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.