How to Update a Session Variable ?

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. #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...
    2. 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...
    3. 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)...
    4. 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...
    5. [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...
  3. #2

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139