PHP/MySQL Database image gallery deletion

whitetigergrowl

New Member
I'm having trouble deleting images from a mysql database using php. The addition of images to the database works great, and it will display/retieve the images no problem, but it won't delete them properly. It doesn't delete the selected image, always the first one in the database. I've tested it using specific filenames and id's so I know it works, it just doesn't seem to target the selected image. The gallery table consists of: id, imagename, assoc_table(category) & assoc_object(page-image-is-attached-to).Hope this makes sense and many thanks in advance.This is the code used to add and display the images:\[code\]$galleryQuery=mysql_query("select * from isgallery where assoc_object = '".$_POST['id']."'"); echo '<ul class="gallery">'. PHP_EOL; while($galleryResult=mysql_fetch_array($galleryQuery)) { echo '<li><img src="http://stackoverflow.com/images/properties/gallery/'.$galleryResult['imagename'].'" alt="'.$galleryResult['id'].'" width="120" height="120" class="image" /><br /> <label for="delGallery"><input type="checkbox" name="delGallery" value="http://stackoverflow.com/questions/3752650/1" /> Delete this image?</label><br /> </li> '. PHP_EOL; } echo '</ul><br /><br />' . PHP_EOL; echo '<label for="galleryFile">Add Image (*.jpg / *.gif): </label><input type="file" name="galleryFile" value=""><br /> '.($_POST['imagename'] ? ' <label for="imagename"></label><img src="http://stackoverflow.com/images/properties/gallery/'.$_POST['imagename'].'" width="120" class="image"><br /> <label for="delGallery"></label><input type="checkbox" name="delGallery" value="http://stackoverflow.com/questions/3752650/1" style="margin:0 0 0 7px;"> Delete this image?<br /> ' : NULL).' \[/code\]This is the code that is used to delete from the database:\[code\]if ($_POST['delGallery']=='1') { file_exists($galleryFileDir.'/'.$_POST['imagename']) ? unlink($galleryFileDir.'/'.$_POST['imagename']) : NULL; unset($_POST['imagename']); $sql = "DELETE FROM isgallery WHERE imagename = '".$_POST['imagename']."'"; mysql_query($sql); } \[/code\]
 
Back
Top