this is following on from this question I posted yesterday - my question from yesterday
The answer given by webbiedave seemed to work but continued to delete the last image in the group rather than the one selected through the checkbox. When I print_r($_POST);
none of these images can be found anywhere in the printed array. Within the page/form I have other image uploads and text inputs which are all written to the main table 'isadmin' and print_r($_POST);
displays them all fine.
There seems to be a problem with the images that are being pulled-in from the isgallery table and the fact that they seem to 开发者_如何转开发be isolated from the rest of the items within the form and are not being picked up when $_POST['delGallery']=='1'
.
Any help greatly appreciated. S
If you intend to delete an array of images, you can change your checkbox code to:
<label for="delGallery<?php echo $galleryResult['id'] ?>"><input id="delGallery<?php echo $galleryResult['id'] ?>" type="checkbox" name="gallery_ids[]" value="<?php echo $galleryResult['id'] ?>" /> Delete this image?</label><br />
Now you don't need the hidden input that you had in your other code. PHP will create an array for you, so in your delete code you can do something like:
if (!empty($_POST['gallery_ids'])) {
foreach ($_POST['gallery_ids'] as $galleryId) {
$sql = "DELETE FROM isgallery WHERE id = ".mysql_real_escape_string($galleryId);
mysql_query($sql);
}
}
Again, you'll want ensure proper sanitizing/validating/escaping code is used.
精彩评论