PHP code does not delete any record in DB

kxaclan

New Member
I am trying to represent All users in a web site and allow the admin to delete checked records. I searched a lot on this website and although I found a lot of similar questions, some of them answered, none of them work for me. :(here is my code \[code\]<?php// Connect to server and select databse.$sql="SELECT * FROM $tbl_name";$result=mysql_query($sql);?><table width="400" border="0" cellspacing="1" cellpadding="0"><tr><td><form name="form1" method="post" action=""><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr><td bgcolor="#FFFFFF">&nbsp;</td><td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td></tr><tr><td align="center" bgcolor="#FFFFFF">#</td><td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td><td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td><td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td><td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td></tr><?phpwhile($rows=mysql_fetch_array($result)){?><tr><td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="http://stackoverflow.com/questions/15914119/<? echo $rows['Id']; ?>"></td><td bgcolor="#FFFFFF"><? echo $rows['Id']; ?></td><td bgcolor="#FFFFFF"><? echo $rows['volunteersname']; ?></td><td bgcolor="#FFFFFF"><? echo $rows['volunteersname']; ?></td><td bgcolor="#FFFFFF"><? echo $rows['volunteersname']; ?></td></tr><?php}?><tr><td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="http://stackoverflow.com/questions/15914119/Delete"></td></tr><?php// Check if delete button active, start this if (isset($_POST['delete']) && isset($_POST['checkbox'])) { foreach($_POST['checkbox'] as $del_id){ $del_id = (int)$del_id; $sql = "DELETE FROM volunteers WHERE Id = $del_id"; mysql_query($sql); } echo "Done";//header('Location: topics.php');}// if successful redirect to delete_multiple.php //echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";?></table></form></td></tr></table>\[/code\]Also, I wonder which is better - to put a check box in front of each record and at the end put a button to delete what has been checked ORPut a delete link in front each record?I know it's the same function but from usability point of view ^_^
 
Top