Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MySQL Database image gallery deletion
    primarykey
    data
    text
    <p>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. </p> <p>The gallery table consists of: id, imagename, assoc_table(category) &amp; assoc_object(page-image-is-attached-to).</p> <p>Hope this makes sense and many thanks in advance.</p> <p>This is the code used to add and display the images:</p> <pre><code>$galleryQuery=mysql_query("select * from isgallery where assoc_object = '".$_POST['id']."'"); echo '&lt;ul class="gallery"&gt;'. PHP_EOL; while($galleryResult=mysql_fetch_array($galleryQuery)) { echo '&lt;li&gt;&lt;img src="../../images/properties/gallery/'.$galleryResult['imagename'].'" alt="'.$galleryResult['id'].'" width="120" height="120" class="image" /&gt;&lt;br /&gt; &lt;label for="delGallery"&gt;&lt;input type="checkbox" name="delGallery" value="1" /&gt; Delete this image?&lt;/label&gt;&lt;br /&gt; &lt;/li&gt; '. PHP_EOL; } echo '&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;' . PHP_EOL; echo '&lt;label for="galleryFile"&gt;Add Image (*.jpg / *.gif): &lt;/label&gt;&lt;input type="file" name="galleryFile" value=""&gt;&lt;br /&gt; '.($_POST['imagename'] ? ' &lt;label for="imagename"&gt;&lt;/label&gt;&lt;img src="../../images/properties/gallery/'.$_POST['imagename'].'" width="120" class="image"&gt;&lt;br /&gt; &lt;label for="delGallery"&gt;&lt;/label&gt;&lt;input type="checkbox" name="delGallery" value="1" style="margin:0 0 0 7px;"&gt; Delete this image?&lt;br /&gt; ' : NULL).' </code></pre> <p>This is the code that is used to delete from the database:</p> <pre><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></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload