Can't get checkbox selections to delete SQL records with php
Posted: Sat Dec 03, 2011 10:57 pm
I'm having a tough time getting this code to delete records from my SQL table. Once again, I know it's something I'm doing wrong but I can't figure it out. Everything is displayed properly, including the checkboxes and the delete button but when I select one of the checkboxes and click on the delete button the page just refreshes. I hope someone can help. Thanks.
Code: Select all
<table>
<tr>
<td><form name="form1" method="post" action="">
<table>
<?php
if(mysql_num_rows($result) == 0)
{
echo "<h5 align=\"center\">","None","</h5>";
} else {
$r_n = 1;
while ($row = mysql_fetch_array($result))
{
$imgs_img_name = $row['img_name'];
$imgs_img_desc = $row['img_desc'];
$imgs_img_date = $row['img_date'];
$imgs_img_date = strtotime( $imgs_img_date );
$imgs_img_date = date( 'm-d-Y', $imgs_img_date );
?>
<h7>Delete?
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['img_name']; ?>"><br />
<?php
echo substr($imgs_img_name, 11, 50),"</h7>";
echo "<img align=\"center\" src=\"/uploader/uploaded_files/$imgs_img_name\" HEIGHT = \"75\" WIDTH = \"125\">";
echo "<h5 align=\"right\">";
echo $imgs_img_desc,"<br />","</h5>";
echo "<h4 align=\"left\">","Uploaded: ",$imgs_img_date,"</h4><br />";
$r_n++;
}
echo "<input name=\"delete\" align=\"center\" type=\"submit\" id=\"delete\" value=\"Delete\">";
if($delete)
{
for($i=0;$i<$count;$i++)
{
$del_id = $checkbox[$i];
$sql = "DELETE FROM Images.$curr_mbr WHERE `img_name`='$del_id'";
$result = mysql_query($sql);
}
if($result)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=member-profile.php\">";
}
}
}
mysql_free_result($result);
?>
</table>
</form>
</td>
</tr>
</table>