Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Session Variable - How do I keep it?

Status
Not open for further replies.

monoone

Programmer
May 24, 2002
219
0
0
US
I think I have created a session Variable. Now, I want to be able to create a ContactType and apply the AccountID to the ContactType. The AccountID belongs to the user that has logged on (the session). How do I keep this session going? It seems to break when I Fill out a form and submit it. Note that my action page resides on the same page.

Here is the Form:

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

<CFQUERY NAME="GetAccount" DATASOURCE="#request.datasource#" DBTYPE="ODBC">
SELECT *
FROM Account
<cfif #session.AccountID# IS NOT 0>
WHERE AccountID = #Session.AccountID#
</cfif>
</CFQUERY>

<!-- FORM STARTS HERE -->
<FORM ACTION="#" METHOD="post">
<INPUT TYPE="hidden" NAME="AccountID" VALUE="#session.AccountID#">
<TABLE CELLSPACING="2" CELLPADDING="2" BORDER="0">
<TR>
<TD VALIGN="middle">Contact Type</TD>
<TD VALIGN="middle"><INPUT TYPE="text" NAME="ContactType" VALUE="" SIZE="25"></TD>
</TR>

<TR>
<TD COLSPAN="2" ALIGN="center" VALIGN="top">
<BR>
<BR>
<INPUT TYPE="submit" NAME="Add" VALUE="Add">&nbsp;&nbsp;&nbsp;<INPUT TYPE="reset" NAME="Reset" VALUE="Reset"></TD>
</TR>
</TABLE>
</FORM>
<!-- FORM ENDS HERE -->
---------------------------------

Then here is the code on the top of the page:

<CFIF IsDefined("FORM.add")>

<CFQUERY NAME="AddContactType" DATASOURCE="#request.datasource#" DBTYPE="ODBC">
INSERT INTO ContactType
(ContactType, AccountID)

VALUES ('#FORM.ContactType#', #FORM.AccountID#)
</CFQUERY>

</CFIF>

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

Any ideas?
 
Are you getting an error?



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
You don't sound to confidant when you say "I think I created a session variable"

In cf you have to tell it to manage session variables. in your Application.cfm file be sure you add something that looks like this.

Code:
<cfsetting enablecfoutputonly = "yes">
<cfapplication name = "myAppName" sessionmanagement = "yes" setclientcookies = "yes" sessiontimeout = "#createtimespan(0,0,10,0)#">
<cfsetting enablecfoutputonly = "no">

This will allow session variables to last 10 minutes. If you want to change the time change the "10" to the number of minutes you want to have.

be sure you change the application's name attribute to something more suited than "myAppName". If you use the same application name for different "applications" your session variables will cross.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Here is what I have on my Application Page:

---------------------------------------------
<cfapplication name="LoudNews"
clientmanagement="Yes"
sessionmanagement="Yes"
setclientcookies="Yes"
clientstorage="Cookie"
sessiontimeout=#CreateTimeSpan(0,0,45,0)#>

<CFIF NOT isdefined("application.init")>
<CFLOCK SCOPE="APPLICATION" TIMEOUT="10" TYPE="EXCLUSIVE">
<CFSET application.ItemDelimiter = "::&&::">
<CFSET application.init = 1>
</CFLOCK>
</CFIF>
-------------------------------------------------

Here is the error
------------------------------------------------

Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)


[Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression '#session.AccountID#'.



The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (4:1) to (4:79).


Date/Time: 10/25/04 18:01:13
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; SV1; .NET CLR 1.1.4322)
Remote Address: 65.175.220.101
HTTP Referer:
 
Is session.AccountID a numeric datatype in the database? If so, don't use the single quotes around it.



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Syntax error in date in query expression '#session.AccountID#'? are you trying to use an accountID in a date field?
please post the page you're having this error on.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Thanks, I figured it out. All I had to do was get rif og the hidden field:

<INPUT TYPE="hidden" NAME="AccountID" VALUE="#session.AccountID#">

Then just put #session.AccountID# in the VALUES in the SQL.

Thanks for the help though.

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top