Jump to content

DELETE FROM not working


3cool4school

Recommended Posts

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();
}

Link to comment
https://forums.phpfreaks.com/topic/262519-delete-from-not-working/
Share on other sites

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.