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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set primary key as session variable

Status
Not open for further replies.

DeZiner

Programmer
Joined
May 17, 2001
Messages
815
Location
US
I am running a query that checks id and zip to check for username/password

I can't seem to query the id field and set it as a seesion variable. If I use another column in the original query rather than id the process works fine?????????

<cfquery name=&quot;GetUser&quot; datasource=&quot;mySource&quot;>
SELECT *
FROM myTable
WHERE id='#Form.id#' and zip='#Form.zip#'
</cfquery>

<!--- Check if we have a winner! --->
<cfif GetUser.RecordCount gt 0>

<!--- Store the user id in session variables and cookies. --->
<cfset Session.id = GetUser.id>
<cfcookie name=&quot;id&quot; value=&quot;#GetUser.id#&quot; expires=&quot;NEVER&quot;> DeZiner
gear.gif width=45 align=left
When the gears stop turning,
we all stop learning.
 
Got it!

Remove the singal quote from the #id# query!

Can someone tell me why this worked?

Thanks DeZiner
gear.gif width=45 align=left
When the gears stop turning,
we all stop learning.
 
Hey DeZiner,

Whenever you do comparisions on date or numeric fields (autonumber included), you don't use quotes. This is just the SQL syntax rule. For any type of text field, the single quotes are required.

ex. numeric comparision
where ID = 5

ex. text field comparison
where name = 'John'
where name like 'John'

Hope this helps,
GJ
 
Hi all, sorry I'm a bit late on this thread, but I've just had the same problem. It was resolved by not using session.id (this may be a 'reserved' keyword!?!), instead using session.profileID as this now works.
e.g.

<CFSET session.profileID = getUser.id>


anyone know if 'session.id' is reserved?

Neil B
 
Neil, Actually removing the quote fixed the problem as Gunjack says be careful with quotes on strings and integers DeZiner
gear.gif width=45 align=left
When the gears stop turning,
we all stop learning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top