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]<?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($sq l) or die(mysql_error ());
?>[/PHP]
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 '785fdf3a1a755e 2a2189fa3028f33 f22' in 'where clause'
Thanks in advance.
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]<?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($sq l) or die(mysql_error ());
?>[/PHP]
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 '785fdf3a1a755e 2a2189fa3028f33 f22' in 'where clause'
Thanks in advance.
Comment