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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.