Ask a Question related to Macromedia ColdFusion, Design and Development.
-
smokin_joe #1
How to Update a Session Variable ?
Trying here, as I have not received any responses in the Advanced
forum...Thanks for any help !
In its original application, the following "borrowed" code enables data to be
written to a session variable.
I would like to change this so that, a previously established variable, can at
this time be Updated with the current contents.. That is, initially I set the
session variable to capture the Customer ID. In another screen, I want to add
additional data to the original variable. So, I would like to check to see if
the CustomerID is present and if there are NO products already there I want to
UPDATE that row with the new information.
Then, if the CustomerID and same ProductID are there, I want to update that.
I hope that I am making sense.... what this code is currently doing is ADDing
a new row and not updating the appropriate one.
Can anyone offer any advice?
<!--- Update shopping cart --->
<cfelseif attributes.action is "update">
<!--- Loop through basket and remove selected items --->
<cfset newBasket = queryNew("CustomerID, ProductID, ProductName, Quantity,
saleDate")>
<cfloop query="session.basket">
<!--- Add anything that isn't in the delete list --->
<cfif not listFind(attributes.productID, productID)>
<cfset tempValue = queryAddRow(newBasket)>
<cfset tempValue = querySetCell(newBasket, "saleDate", saleDate)>
<cfset tempValue = querySetCell(newBasket, "CustomerID", CustomerID)>
<cfset tempValue = querySetCell(newBasket, "ProductID", ProductID)>
<cfset tempValue = querySetCell(newBasket, "ProductName", ProductName)>
<cfset tempValue = querySetCell(newBasket, "Quantity", quantity)>
</cfif>
</cfloop>
<!--- set the basket to the new values --->
<cfset session.basket = newBasket>
<!--- Add product to query --->
<cfelseif attributes.action is "add">
<!--- check to see if the product is in the baset already --->
<cfset productRow = listFind(valueList(session.basket.productID),
attributes.productID)>
<!--- Product is in basket, update quantity --->
<cfif productRow neq 0>
<!--- determine the new quantity and the correct row --->
<cfset oldQuantity = listGetAt(valueList(session.basket.quantity), productRow)>
<cfset newQuantity = attributes.quantity + oldQuantity>
<cfset tempValue = querySetCell(session.basket, "Quantity", newQuantity,
productRow)>
<!--- Product is not in basket, add it --->
<cfelse>
<cfset tempValue = queryAddRow(session.basket)>
<cfset tempValue = querySetCell(session.basket, "saleDate", "#Now()#")>
<!---<cfset tempValue = querySetCell(session.basket, "saleDate", "#Now()#")>
--->
<cfset tempValue = querySetCell(session.basket, "CustomerID",
attributes.CustomerID)>
<cfset tempValue = querySetCell(session.basket, "ProductID",
attributes.ProductID)>
<cfset tempValue = querySetCell(session.basket, "ProductName",
attributes.ProductName)>
<cfset tempValue = querySetCell(session.basket, "Quantity",
attributes.quantity)>
</cfif></cfif>
smokin_joe Guest
-
#39634 [NEW]: session variable and normal variable
From: erhanbaris at gmail dot com Operating system: Win Xp SP1 PHP version: 5.2.0 PHP Bug Type: Variables related Bug... -
session variable and IE
Hi there, I have a session variable that holds an user name, after user logs in. All works just fine in development environment (Intranet) for IE... -
Session Variable in IIS 5
Hi, i can't use a Session variable in IIS 5, when i try to assign a value send to me next erro messages "Microsoft VBScript runtime (0x800A000D)... -
Datalist - how (if) to use a sub variable or session variable in the footer?
Hi, sorry to be greedy with all my posts lately, but can you tell I'm doing new things this week? I've just done my first datalist (a simple... -
[SESSION] Session variable deleted prior to command?
Hi all, I'm developing a database system on my local computer (OS/version details at bottom) with a simple user authentication using sessions. On... -
vkunirs #2
Re: How to Update a Session Variable ?
Hi
Are you able to come to this line. i mean is this line is executing?
<!--- Product is in basket, update quantity --->
<cfif productRow neq 0>
<!--- determine the new quantity and the correct row --->
<cfset oldQuantity = listGetAt(valueList(session.basket.quantity),
productRow)>
<cfset newQuantity = attributes.quantity + oldQuantity>
<cfset tempValue = querySetCell(session.basket, "Quantity",
newQuantity, productRow)>
First you debug that the execution is coming to this loop
and check value productRow, if it is > 0 then it will update that row
only. even it fails it wont add new record into the query.
vkunirs Guest



Reply With Quote

