Jump to content

[SOLVED] Deleting Multiple Rows?


vozzek

Recommended Posts

Hi all,

 

I've got some php code running an SQL delete to remove rows from my shopping cart table (tbl_cart). It works on individual cart id's, but not when I want the entire cart emptied.

 

tbl_cart looks like this:

ct_id (cart id, this is the primary key)

pd_id (product id)

ct_qty (quantity)

ct_session_id (user's unique session id)

etc...

 

Here's the code:

 

<?php
// current session id
   $sid = session_id();

// $cid passed from view_cart page
// if $cid=0, then empty cart

if ($cid != 0) {	
	$sql  = "DELETE FROM tbl_cart
			 WHERE ct_id = $cid";  // This works
            } else {
    $sql  = "DELETE FROM tbl_cart
			 WHERE ct_session_id = $sid";  // This doesn't work
            }
    $result = mysql_query($sql) or die(mysql_error());
?>

 

If I pass $cid as a whole number, it deletes that row - effectively deleting that item from the cart. But when the user presses the EMPTY CART button, I call the above code by passing $cid as zero. At this point I want all records deleted that match the current user's session id, which is $sid.

 

The error I'm getting is:

 

Unknown column '785fdf3a1a755e2a2189fa3028f33f22' in 'where clause'

 

The crazy variable is of course, the session id.  Thanks in advance.

 

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.