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
https://forums.phpfreaks.com/topic/79320-solved-deleting-multiple-rows/
Share on other sites

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.