joaomagico Posted March 15, 2014 Share Posted March 15, 2014 I have a <a>, on click delete a product from database that is on server, I want to delete the product and the same time delete the image of that product. I using unlink() my code delete the product but don't delete the image and I don't no why someone can tell me what is missing ? if((isset($_GET["remove"])) && ($_GET["remove"] != "")){$idproduct = $_GET["remove"];$sql ="DELETE FROM product WHERE idproduct = '".$idproduct."'";if(mysqli_query($connect, $sql) or die ("Erro")){//the part that don't work $file = $frontpage_url."/images/".$_FILES["imagem"]["name"]; unlink($file);echo "success";}} Quote Link to comment Share on other sites More sharing options...
anatak Posted March 15, 2014 Share Posted March 15, 2014 because you have to delete the file from the path on your file system instead of the url ? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 15, 2014 Share Posted March 15, 2014 the $_FILES array is the information about the file when the file was uploaded. the $_FILES array doesn't exist after that point. what method have you used to associate the row in the product database table with the image that was stored in the $frontpage_url."/images/" folder? Quote Link to comment Share on other sites More sharing options...
joaomagico Posted March 15, 2014 Author Share Posted March 15, 2014 my images came from here $frontpage_url."/images/" I have try like this but still don't work Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 15, 2014 Share Posted March 15, 2014 that might be where your images are stored, but you must specify which image you want to delete, which is why i asked what method have you used to associate the row in the product database table with the image that was stored in the $frontpage_url."/images/" folder? if you have no relationship that tells you which image belongs with which row in the product table, how do you expect to be able to delete the proper image file? Quote Link to comment Share on other sites More sharing options...
joaomagico Posted March 16, 2014 Author Share Posted March 16, 2014 that might be where your images are stored, but you must specify which image you want to delete, which is why i asked what method have you used to associate the row in the product database table with the image that was stored in the $frontpage_url."/images/" folder? if you have no relationship that tells you which image belongs with which row in the product table, how do you expect to be able to delete the proper image file? Yes that is my problem how I associate the image with the row I want to delete ? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 16, 2014 Share Posted March 16, 2014 It's a little late now. If the database doesn't have the image name saved with the product, and if the image name is not simply product id, no amount of programming is going to join them for you. You have to develop a scheme to connect the two before you can continue with this project. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.