3cool4school Posted May 14, 2012 Share Posted May 14, 2012 Hi all, this is probably the easiest thing and I may have just been staring at the screen for too long but one of my DELETE FROM queries isn't working. I created a cart and in the admin area when an admin deletes the product it is supposed to delete it from the 'Products' table and also all the sizes from the 'Sizes_List' table. Right now it is only being deleted from the Products table and not the Sizes_List table.. here is the snippet.. any help would be greatly appreciated. if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $deletefrom_sizes = mysql_query("DELETE FROM Sizes_List WHERE product_id = '$id_to_delete'"); $sql = mysql_query("DELETE FROM Products WHERE product_id='$id_to_delete' LIMIT 1"); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../user/rent/inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: addproduct.php"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/262519-delete-from-not-working/ Share on other sites More sharing options...
Maq Posted May 14, 2012 Share Posted May 14, 2012 Are you sure there's no errors? Have you tried this query in mysql directly? Quote Link to comment https://forums.phpfreaks.com/topic/262519-delete-from-not-working/#findComment-1345354 Share on other sites More sharing options...
3cool4school Posted May 14, 2012 Author Share Posted May 14, 2012 yup, no errors, and it works in phpmyadmin and deletes all corresponding rows. Quote Link to comment https://forums.phpfreaks.com/topic/262519-delete-from-not-working/#findComment-1345355 Share on other sites More sharing options...
mrMarcus Posted May 14, 2012 Share Posted May 14, 2012 Please add the following to your query: $deletefrom_sizes = mysql_query("DELETE FROM Sizes_List WHERE product_id = '$id_to_delete'") or die(mysql_error()); Edit: off-topic and nothing to do with possible issue at this time, but if your `product_id` is INT based in the table, then wrapping it in single quotes will not allow any index to perform as expected. E.g. 12345 If `product_id` is VARCHAR or something similar, then quotes are needed; and please, sanitize your variables before tossing them into your queries. But I'm sure you were going to Quote Link to comment https://forums.phpfreaks.com/topic/262519-delete-from-not-working/#findComment-1345358 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.