My question is: how do I get the "delete" button to delete the picture? I know it may be quite simple but I'm not being able to get my head around it without deleting everything in the process.
Hey guys,
My question is: how do I get the "delete" button to delete the picture? I know it may be quite simple but I'm not being able to get my head around it without deleting everything in the process.
It depends om whether the info about the images are stored in a database or not.
If is, then basically in the href I would send the id of the image to a server side script that deleted the info for the image from the database and then deletes the corresponding physical image file for that image id from from the hard disk.
And yeah, that's pretty much of what I had tried. My database rows for each item are as follows:
id, thumbnail, image, category_id and created_at collumns.
However, when I try selecting one of them using their own id (like tirna said) I always select all of them because they're inside a "while". If I get the "delete" button to delete the row with that specific "id" from the database, what will happen is that it will select every row and delete them all instead of just one.
where "imageId" is the image Id for the respective image from the database.
The user then checks the checkboxes for the images they want to delete and then clicks a "Delete" button.
When the "Delete" button is clicked an array called delMe[] containing the id's of the images to be deleted is sent to server side script.
Then the server side script loops through the delMe array of id's and deletes the appropriate records from the database only for those id's in delMe and then deletes the corresponding physical files from disk for those id's.
This way you can delete multiple images on 1 click of the "Delete" button as opposed to deleting 1 image at a time.
alright, so first of the problem solved with that side script, thanks
I used the following code:
Code:
<?php
echo("Image number $_GET[id] successfully deleted");
mysql_query("DELETE from photos WHERE id='$_GET[id]'");
?>
Now I can get to the second part of my question: in the database, for each image, there are 2 links: one for the full sized image and another one for the thumbnail. Is there a way that I can get this delete button to also delete both images from the hard disk they are hosted in?
alright, so first of the problem solved with that side script, thanks
I used the following code:
Code:
<?php
echo("Image number $_GET[id] successfully deleted");
mysql_query("DELETE from photos WHERE id='$_GET[id]'");
?>
Now I can get to the second part of my question: in the database, for each image, there are 2 links: one for the full sized image and another one for the thumbnail. Is there a way that I can get this delete button to also delete both images from the hard disk they are hosted in?
As soon as you have confirmed in your script that the image's record in the database has been deleted you can use unlink() as suggested by antares earlier to delete the physical files for that image from the hard disk.
Bookmarks