Skip to main content
Inspiring
May 9, 2008
Answered

Problem with Session variables

  • May 9, 2008
  • 2 replies
  • 316 views
On page 1 I am setting a session variable based on a users log in:

<cfif NOT IsDefined("SESSION.EmpNo")>
<cfset SESSION.EmpNo = #Form.HREmpNo#>
</cfif>

On page 2, I call the session variable into a query to pre-fill a form, this works fine:

<cfquery name="qEmpInfo" datasource="SelfNom">
SELECT *
FROM tblEmployeeList
WHERE EmployeeNo = #session.EmpNo#
</cfquery>

On the same page, I give the prefilled info hidden tags so I can enter the infor into a table on the following page. qEmpInfo is the query I am hitting successfully with my session variable. Here are my tags:

<cfoutput>#qEmpInfo.EmployeeNo#</cfoutput>
<input type="hidden" name="EmployeeNo" value="#qEmpInfo.EmployeeNo#" />

On the 3rd page, where I try to insert the infor into another table, I am getting an error. Itacts like my session variable is gone.

Error:
Syntax error in date in query expression '#qEmpInfo.EmployeeNo#'.

I entered this code on page 3 to check and it by passes it I assume because it does not find the session variable:

<cfif NOT IsDefined("SESSION.EmpNo")>
<cfoutput>#session.EmployeeNo#</cfoutput>
</cfif>

I set my session time out in the admin to 24 hours, so that should not be the issue. And I have turned on session variables in the Application.cfm:

<cfapplication name="SelfNom"
sessionmanagement="Yes">



Does anyone see something I am doing wrong?
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    Jatrix wrote:
    > Does anyone see something I am doing wrong?

    Well the first thing I noticed is this:
    <cfif NOT IsDefined("SESSION.EmpNo")>
    <cfoutput>#session.EmployeeNo#</cfoutput>
    </cfif>


    'session.empNo' AND 'session.EmployeeNo' are not the same variable. You
    check for the existence for the first and then try to output the second.
    You create a variable named 'employeeNo' in your form. Is that the
    one you meant to be using here? 'form.employeeNo' not 'session.employeeNo'

    2 replies

    Newsgroup_UserCorrect answer
    Inspiring
    May 9, 2008
    Jatrix wrote:
    > Does anyone see something I am doing wrong?

    Well the first thing I noticed is this:
    <cfif NOT IsDefined("SESSION.EmpNo")>
    <cfoutput>#session.EmployeeNo#</cfoutput>
    </cfif>


    'session.empNo' AND 'session.EmployeeNo' are not the same variable. You
    check for the existence for the first and then try to output the second.
    You create a variable named 'employeeNo' in your form. Is that the
    one you meant to be using here? 'form.employeeNo' not 'session.employeeNo'

    Inspiring
    May 9, 2008
    If EmployeeNo is a number field in the database you don't need quotes around it in the query.

    So this:

    '#qEmpInfo.EmployeeNo#'

    Should be this in the query:

    #qEmpInfo.EmployeeNo#

    --
    Ken Ford
    Adobe Community Expert - Dreamweaver
    Fordwebs, LLC
    http://www.fordwebs.com


    "Jatrix" <thejatrix32@yahoo.com> wrote in message news:g01mno$6fj$1@forums.macromedia.com...
    > On page 1 I am setting a session variable based on a users log in:
    >
    > <cfif NOT IsDefined("SESSION.EmpNo")>
    > <cfset SESSION.EmpNo = #Form.HREmpNo#>
    > </cfif>
    >
    > On page 2, I call the session variable into a query to pre-fill a form, this
    > works fine:
    >
    > <cfquery name="qEmpInfo" datasource="SelfNom">
    > SELECT *
    > FROM tblEmployeeList
    > WHERE EmployeeNo = #session.EmpNo#
    > </cfquery>
    >
    > On the same page, I give the prefilled info hidden tags so I can enter the
    > infor into a table on the following page. qEmpInfo is the query I am hitting
    > successfully with my session variable. Here are my tags:
    >
    > <cfoutput>#qEmpInfo.EmployeeNo#</cfoutput>
    > <input type="hidden" name="EmployeeNo" value="#qEmpInfo.EmployeeNo#" />
    >
    > On the 3rd page, where I try to insert the infor into another table, I am
    > getting an error. Itacts like my session variable is gone.
    >
    > Error:
    > Syntax error in date in query expression '#qEmpInfo.EmployeeNo#'.
    >
    > I entered this code on page 3 to check and it by passes it I assume because it
    > does not find the session variable:
    >
    > <cfif NOT IsDefined("SESSION.EmpNo")>
    > <cfoutput>#session.EmployeeNo#</cfoutput>
    > </cfif>
    >
    > I set my session time out in the admin to 24 hours, so that should not be the
    > issue. And I have turned on session variables in the Application.cfm:
    >
    > <cfapplication name="SelfNom"
    > sessionmanagement="Yes">
    >
    >
    >
    > Does anyone see something I am doing wrong?
    >
    >