Answered
Need Help: Understanding Session Variables
Greetings -
Perhaps I am just not understanding how session variables function and
hopefully someone here can assist me in doing so.
I am trying to establish an auto report numbering process for a customer
so that when a person displays a report online, a report number is
generated and stored as a session variable and when all information
is submitted, upload report number and the additional submitted information
to a database. All appears to be working as intended, with the exception of this.
I am using an application.cfm file to set session management and to create a
report number and set that number to a session variable.
When the person displays the report form page, there is an instructional section
for their review, followed by a "Proceed" button to go onto the next section of the
page.
When they click on the "Proceed" button, is when the report number held in a
session variable (application.cfm) should insert into a hidden form field for later
upload, which appears to be occurring.
Now for the part that I don't understand. I thought that as long as a session
had not timed out, the session variable would remain for use and thus if
the report page was refreshed (reloaded) the same session variable would
be used.
What I am experiencing, is that each time the report page is being refreshed,
a new report number is being loaded into the session variable. Am I not
understanding how session variables work? Am I missing some critical
piece of coding or point here?
I have included below the folder structure and files used in the process
for review.
Thanks in advance for any assistance to making this work.
Leonard B
===============================================
===============================================
Folder Structure
-- domain/reports
-- domain/reports/input/
Files
-- domain/reports.cfm <- Entry Point to process
-- domain/reports/application.cfm
-- domain/reports/input/report_form.cfm
====================
application.cfm
<cfapplication name="StartApp" sessionmanagement="yes"
sessiontimeout="#CreateTimeSpan(0,0,20,0)#"
applicationtimeout="#CreateTimeSpan(0,0,2,0)#">
<cfset DSN = "datasource">
<cfquery name="getnumber" datasource="#DSN#">
SELECT report_number
FROM report_numbers
</cfquery>
<cfset Session.report_number = #getnumber.report_number#>
<cfif getnumber.recordcount IS 0>
<cfquery name="insertnumber" datasource="#DSN#">
INSERT INTO report_numbers (report_number) VALUES (1)
</cfquery>
<cfelse>
</cfif>
<cfquery name="updatenumber" datasource="#DSN#">
UPDATE report_numbers
SET report_number = report_number + 1
</cfquery>
====================
report_form.cfm
<cfparam name="Button" default="Start">
<cfif #Button# is "Start">
<cfform action="report_numbers.cfm" method="post" enctype="multipart/form-data">
<input type="submit" name="Button" value="Proceed" />
</cfform>
<cfelseif #Button# is "Proceed">
<div style="padding: 50px 5px 15px 5px">
<cfoutput>#Session.report_number#</cfoutput></div>
</cfif>
Perhaps I am just not understanding how session variables function and
hopefully someone here can assist me in doing so.
I am trying to establish an auto report numbering process for a customer
so that when a person displays a report online, a report number is
generated and stored as a session variable and when all information
is submitted, upload report number and the additional submitted information
to a database. All appears to be working as intended, with the exception of this.
I am using an application.cfm file to set session management and to create a
report number and set that number to a session variable.
When the person displays the report form page, there is an instructional section
for their review, followed by a "Proceed" button to go onto the next section of the
page.
When they click on the "Proceed" button, is when the report number held in a
session variable (application.cfm) should insert into a hidden form field for later
upload, which appears to be occurring.
Now for the part that I don't understand. I thought that as long as a session
had not timed out, the session variable would remain for use and thus if
the report page was refreshed (reloaded) the same session variable would
be used.
What I am experiencing, is that each time the report page is being refreshed,
a new report number is being loaded into the session variable. Am I not
understanding how session variables work? Am I missing some critical
piece of coding or point here?
I have included below the folder structure and files used in the process
for review.
Thanks in advance for any assistance to making this work.
Leonard B
===============================================
===============================================
Folder Structure
-- domain/reports
-- domain/reports/input/
Files
-- domain/reports.cfm <- Entry Point to process
-- domain/reports/application.cfm
-- domain/reports/input/report_form.cfm
====================
application.cfm
<cfapplication name="StartApp" sessionmanagement="yes"
sessiontimeout="#CreateTimeSpan(0,0,20,0)#"
applicationtimeout="#CreateTimeSpan(0,0,2,0)#">
<cfset DSN = "datasource">
<cfquery name="getnumber" datasource="#DSN#">
SELECT report_number
FROM report_numbers
</cfquery>
<cfset Session.report_number = #getnumber.report_number#>
<cfif getnumber.recordcount IS 0>
<cfquery name="insertnumber" datasource="#DSN#">
INSERT INTO report_numbers (report_number) VALUES (1)
</cfquery>
<cfelse>
</cfif>
<cfquery name="updatenumber" datasource="#DSN#">
UPDATE report_numbers
SET report_number = report_number + 1
</cfquery>
====================
report_form.cfm
<cfparam name="Button" default="Start">
<cfif #Button# is "Start">
<cfform action="report_numbers.cfm" method="post" enctype="multipart/form-data">
<input type="submit" name="Button" value="Proceed" />
</cfform>
<cfelseif #Button# is "Proceed">
<div style="padding: 50px 5px 15px 5px">
<cfoutput>#Session.report_number#</cfoutput></div>
</cfif>