Variable is being run twice, and is "not defined" thesecond time around! - Cold Fusion

This is a discussion on Variable is being run twice, and is "not defined" thesecond time around! - Cold Fusion ; Hello~ I have kind of a weird problem going on. I am passing in a URL variable from the first page of an application to the second one. I know it is passing correctly onto my second page, because I ...

+ Reply to Thread
Results 1 to 7 of 7

Variable is being run twice, and is "not defined" thesecond time around!

  1. Default Variable is being run twice, and is "not defined" thesecond time around!

    Hello~

    I have kind of a weird problem going on. I am passing in a URL variable from
    the first page of an application to the second one. I know it is passing
    correctly onto my second page, because I can output it. However... The variable
    is set at the top of the page in the <head> tags, above and outside a <cfif
    isDefined ('form.submit')>... do this</cfif>. The form itself is in the body of
    the page. So, when I navigate to the form page, my variable displays, but then
    when I hit the submit button, it tells me that same variable is not defined,
    even though it's not a part of the cfif isDefined function, and has already
    been successfully defined when the page loaded initially. Does this make any
    sense? Please help!



    Variable Set:

    <cfset firmID = #firmID#>

    -- I am able to output this onto the page before the user fills out the form
    and hits submit--

    <cfif isDefined('form.submit')>
    --Do various operations using #firmID#-- it says that it is not defined--
    </cfif>

    Error:

    Variable FIRMID is undefined.

    The error occurred in line 78

    76 : <!--- Set Variables for Firm TID --->
    77 :
    78 : <cfset firmID = #firmID#>


  2. Default Re: Variable is being run twice, and is "not defined" the secondtime around!

    semi star gazer wrote:
    >
    > Variable Set:
    >
    > <cfset firmID = #firmID#>
    >


    This is a really weird line of code. What are you trying to do here?

    You are setting the variable firmID to the value of the variable firmID.
    Doesn't that seem a little circular? I suspect you are having a
    scoping issue and this may or may not be working because of CF generous
    nature to scan many scopes for a variable name if you do not provide the
    scope to be used. But I don't know enough about your code to say for sure.


  3. Default Re: Variable is being run twice, and is "not defined"the second time around!

    You're right, it is repetitive, but unfortunately removing it didn't solve my
    problems! The variable still displays when the user gets to the page, but I get
    the " Variable FIRMID is undefined" upon submit. The query that it is hanging
    on is not inside the <cfif is defined form.submit> tags, so i'm not even sure
    why it is running again. I am assuming it's something about how I have the
    query laid out, but I don't know what to change!

    In body:

    <cfoutput>
    <p><strong>#firmID#</strong></p>

    THIS WORKS AND DISPLAYS CORRECTLY

    -------------------------------------

    Code that throws error:

    <cfquery name="getFirmInfo" datasource="OCI">

    SELECT
    *
    FROM
    firms
    WHERE
    firms.id = #firmID#
    </cfquery>

    ---------------------------------
    Error:

    Variable FIRMID is undefined.

    The error occurred in line 88

    82 : <cfquery name="getFirmInfo" datasource="OCI">
    83 : SELECT
    84 : *
    85 : FROM
    86 : firms
    87 : WHERE
    88 : firms.id = #firmID#
    89 : </cfquery>


  4. Default Re: Variable is being run twice, and is "not defined"the second time around!

    I'm having a little trouble following you on this since you are only showing
    bits and pieces of your code, but...
    It appears to me that firmID is not getting submitted in the form. You don't
    show your form code, so I'm guessing.
    Can you confirm that formID is indeed a value inside the form tag?

    I would suggest highly that you scope your variables. That prevents a lot of
    confusion and can make code a lot easier to understand. Things like <cfset
    firmID = #firmID#> really serve no purpose, but <cfset variables.firmID =
    #form.firmID#> could possibly be useful.

    Once you get this figured out, I would also suggest researching the use of the
    <cfqueryparm> tag.



  5. Default Re: Variable is being run twice, and is "not defined"the second time around!

    [q]Originally posted by: semi star gazer
    Hello~

    I have kind of a weird problem going on. I am passing in a URL variable from
    the first page of an application to the second one. I know it is passing
    correctly onto my second page, because I can output it. However... The variable
    is set at the top of the page in the <head> tags, above and outside a <cfif
    isDefined ('form.submit')>... do this</cfif>. The form itself is in the body of
    the page. So, when I navigate to the form page, my variable displays, but then
    when I hit the submit button, it tells me that same variable is not defined,
    even though it's not a part of the cfif isDefined function, and has already
    been successfully defined when the page loaded initially. [/q]
    My guess is that you didn't do anything to pass the variable from page 2 to
    page 3. Page 3 only knows about what page 2 sent it. It knows nothing about
    what page 1 sent page 2.



  6. Default Re: Variable is being run twice, and is "not defined"the second time around!

    I would also mention that if you are passing the value via a URL variable, you
    should definitely try and add some parameter security before you use it in a
    SQL statement.

    SELECT *
    FROM firms
    WHERE
    firms.id = #firmID#

    is highly vulnerable to SQL injection and cross site scripting. Try instead:

    SELECT *
    FROM firms
    WHERE
    firms.id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#firmID#">

    that should give you some basic protection.

    From what you've described as your problem, it sounds like Dan's suggestion is
    most likely the solution. You said you passed a URL variable from Page1 to
    Page2, then submit a form on Page2 to Page3. unless you pass the variable as a
    URL variable in the form's action attribute or as a hidden field in the form,
    the variable won't be present on Page3.





  7. Default Re: Variable is being run twice, and is "not defined"the second time around!

    Just so you know, while cfqueryparam does many good things, protecting you from cross site scripting is not one of them.

+ Reply to Thread