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

CFQuery Based on a session variable

Status
Not open for further replies.

SteelDragon

Programmer
Feb 1, 2001
134
US
Ok, here's what I want to do, I want to select information from my database specific to the user that has loged into the site. Kinda like this: I log in, it sets a session variable based on my username, I want to have a query that goes somethin like:

Select * from table Where userid = #Session.UserloggedIn#

I tried something similar to that with no go, I even tried putting CFOutput on it and still no go.

Any ideas?

SteelDragon
 
Hey Steel,

I don't see anything wrong with your query as long as the "userid" field is a numeric field. I assume your table's name isn't table as that is most likely a reserved word in your database or at least in CF.

What problem are you having with the code? Is it generating an error or is it simply not returning the information you expect? If it's not returning the info you expect, I would output the session variable just before the query to make sure you have the correct value at the time the query runs and also output the queryName.recordcount variable to see whether you're returning one, multiple, or no records.

GJ
 
GJ
I actually found it myself right after I posted. It was the stupidest little thing...

<CFQUERY name=&quot;GetRecord&quot; dataSource=&quot;GSHQ&quot; maxRows=1>
SELECT *
FROM Roster
WHERE Roster.UserName = '#Session.USERID#'
</CFQUERY>

Notice on my #Session.UERID# the little single quotes, I was missing them in my original query, I just overlooked them I guess. Sometimes it helps to post here and relook/rethink your original plan.

Thanks,

SteelDragon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top