Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

delete images from database

$
0
0

hi, I'm kind of confused and rookie about the delete image file name from database, I have five images file name  in database  and store image file in the folder, each table column name is  (image_1, image_2, images_3, image_4, image_5).

 
In html , each image have delete button under bottom of image for up to five images.
 
Let say that I want to delete 'image_3" by pressing button, how can i write that code to make sure that i can delete that images file name ONLY from database instead of delete rest of row!
 
i wrote code but not sure working right...
button 
 
<a href='inventory_list.php?deleteid=$id'>delete</a>
 
<?php 
 
 
if (isset($_GET['yesdelete_image_3'])) {
// remove item from system and delete its picture
// delete from database
$id_to_delete = $_GET['yesdelete'];
$sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error());
// unlink the image from server
// Remove The Pic -------------------------------------------
    $pictodelete = ("../inventory_images/$id_to_delete.jpg");
    if (file_exists($pictodelete)) {
            unlink($pictodelete);
    }
header("location: inventory_list.php"); 
    exit();
}
?>

 

 

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles