Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

delete records AND images?

Posted 12 Apr 2006 23:49:12
1
has voted
12 Apr 2006 23:49:12 Patrick Caruana posted:
ok i have a table called "products" with various fields that get listed in an html table. Set to repeat in that is a form checkbox where the name is the string "del" with a "counter variable" on the end of it that gets 1 added to it each time the recordset gets repeated. the value of the checkbox when checked binds with the productID (the key field in the products table). For testing i have used the command print_r($_POST) on the deleteproduct.php page (the page the form submits to) and it prints the desired result

Array ( [del1] => 9 [del6] => 7 [del7] => 8 )

using the following code on deleteproduct.php i can delete the records from the database
<?php

foreach($_POST as $key => $value){
mysql_connect("localhost", "*********", "**********" or die(mysql_error());
mysql_select_db("studio" or die(mysql_error());
mysql_query("DELETE FROM products WHERE ProductID='" . $value . "'"
or die(mysql_error());
}


?>

however for each product there is a field called "productIMG" that has image names such as "whatever.jpeg". How can u use php to get the name of that file before it deletes the record, and then use that filename to delete the file in the images folder? basically i want to be able to delete the record AND the image related to that record stored in whatever images folder.....thanks for any help

thanks for any help,
patrick

Edited by - da_bomb on 12 Apr 2006 23:56:37

Edited by - da_bomb on 13 Apr 2006 00:34:41

Reply to this topic