Jump to content

Problem with selecting and deleting multiple database entries


roondog

Recommended Posts

I am working on a gallery that allows a user to upload and delete pictures. So far I have the uploading working fine but have had various problems with deleting. My idea is to have a form with all the pictures showing and each one having a check box. The problem i've had is getting more than one picture to delete. Is there a special way to handle checkboxes. I can't find my code at the moment ( I might have deleted it in frustration) but will post it when I do find it/ re-do it.

Link to comment
Share on other sites

i assume you save the uploaded pictures to a directorythe html form can be like this

<form action='?' method='post'><input type='checkbox' name='delete_picture[]' value='picture_name1.jpg'><input type='checkbox' name='delete_picture[]' value='picture_name2.jpg'><input type='checkbox' name='delete_picture[]' value='picture_name3.jpg'><input type='submit'></form>

and the php

foreach ($_POST['delete_picture'] as $picture){	unlink($picture);}

this is a very simple way to do it, so it is not secure

Link to comment
Share on other sites

Thanks for that would it work if I didforeach ($_POST['delete_picture'] as $picture){ DELETE FROM table_name;}or would it be better asDELETE FROM table_name WHERE pic_name = $_POST['delete_picture'];or am i getting it completely wrongI should have explained that I have the picture names in a database and I call them from that for the gallery.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...