473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Delete problem...

40
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($sql) 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 '785fdf3a1a755e2a2189fa3028f33f22' in 'where clause'

Thanks in advance.
Nov 28 '07 #1
2 1462
amitpatel66
2,367 Expert 2GB
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($sql) 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 '785fdf3a1a755e2a2189fa3028f33f22' in 'where clause'

Thanks in advance.
This is beacuse the session id value that is passed is very large as shown above.

Does the table has user_id column?
I would suggest you to use user_id instaed of session_id
Nov 29 '07 #2
mwasif
802 Expert 512MB
If ct_session_id is of type VARCHAR/CHAR then use single quotes around value i.e.
[PHP]$sql = "DELETE FROM tbl_cart
WHERE ct_session_id = '$sid'";[/PHP]
Nov 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
2
by: Cornelius Buschka | last post by:
Hi, we saw the following problem: We deleted all rows from a table B referencing table A (~500000 records). No problem, but the following try to delete all records from table A (~180000) lead...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
2
by: Bob Tinsman | last post by:
This problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2. I've found that if I have an XML node expression that ends in a filter, I can't use it with the delete operator. In the following...
6
by: radishcarrot | last post by:
Hi, I am rather new to C++ and an invalid exception has occurs in my system which I have absolutely no idea as to why it happens. Please help! Thank you. I have created a method which takes in...
6
by: Lighter | last post by:
Big Problem! How to overload operator delete? According to C++ standard, "A deallocation function can have more than one parameter."(see 3.7.3.2); however, I don't know how to use an overloaded...
5
by: rn5a | last post by:
The .NET 2.0 documentation states the following: When using a DataSet or DataTable in conjunction with a DataAdapter & a relational data source, use the Delete method of the DataRow to remove...
9
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.