Skip to main content
Inspiring
February 18, 2010
Question

passing a variable into a database that is not within a form field...

  • February 18, 2010
  • 1 reply
  • 644 views

Is there any way to pass a variable onto a database that is not within a form field? I have a page in DW to update a database with values passed from the DW update page. Typically when values are passed from a page to a database, email, etc you will have to do a #form.fieldname#. I however have a value that is not in a form field, it is an aggregated function that displays a total when the form is updated. yet I would like to have that variable passed to and  updated in my database. Since the variable is not in situated in a field I cannot use the #form.fieldname#. Is there a way to do that?

CK

    This topic has been closed for replies.

    1 reply

    Inspiring
    February 18, 2010

    This statement:

    Typically when values are passed from a page to a database, email, etc you will have to do a #form.fieldname#.

    is not true.  Not only do you not have to do that, in fact, in many cases it would be an indication that you did not validate your user input.

    You can reference any type of variable in a cfquery.  For your own situation, I suggest that you simply try it.

    Inspiring
    February 18, 2010

    Thank for the reply. i may be doing something in error. below is the coding i am using:

    This is how the code looks:

    <cfquery name=”menu_1” database=”dinner_program”>

    SELECT SUM(e1_menu*Entree_1_cost+e2_menu*Entree_2_cost+s1_menu*side_1_cost+s2_menu*side_2_cost+s3_menu*side_3_cost+d1_menu*dessert_1_cost+d2_menu*dessert_2_cost+delivery_fee) AS order_total

    FROM order_log

    WHERE order_id=#edit_order_log.order_id#

    </cfquery>

    Everywhere on my update page I put the:

    <cfoutput>#menu_1.order_total#</cfoutput>

    it will display the resulting price.

    On my action page can I update my database with the following select code:

    <cftransaction>

    <cfupdate datasource=”dinner_program”

    Tablename=”order_log”

    WHERE talley=<cfoutput>#menu_1.order_total#</cfoutput>

    </cftransaction>

    ilssac
    Inspiring
    February 18, 2010

    To do what you want you have to grow out of the <cfupdate...> and <cfinsert...> tags that are for simple, beginners task and graduate to the <cfquery....> tag that allows you to build your own SQL statements with any variable or functions you care to apply to the problem at hand.

    With the <cfquery....> tag, you don't even need the <cfoutput> block to render your variables as the <cfquery...> knows to do that already.  In reality you only ever use <cfoutput> blocks when you have dynamic content you want output to a client.

    To get you started your <cfupdate...> would translate to a <cfquery ....> something like this.

    <cfquery datasource="dinner_program">

    UPDATE order_log

    SET aField = aValue

    WHRE talley = #menu_1.order_total#

    </cfquery>

    The documention on the <cfquery...> tag should give you plenty of other information to get you going.