Cannot set Session variable as Integer

Good morning,
I’m having trouble setting a SESSION.variable to type Integer.
Specifically, the problem is the MEMBERID session variable

Inside Application.cfm I have this…

CLIENTMANAGEMENT="Yes"
SESSIONMANAGEMENT="Yes"
applicationtimeout="#CreateTimeSpan(0,0,30,0)#">

And in the Database, MemberID is defined as INT(10)

Then in the template that gets the memberid from the database I have this…

 <CFOUTPUT Query = 'authenticate'>
 <CFSET SESSION.verified = "Yes">
 <CFSET SESSION.memberID = #memberID#>
 </CFOUTPUT>

Then I try to store user data into the database…

<CFQUERY Name="AddNewEntry" datasource="Earthmatters">
Insert into entries (date, memberid,personid,year,month,day,time,event,entryprivacy) VALUES (Now(), <cfqueryparam value=SESSION.memberID CFSQLType = "CF_SQL_INTEGER">, <cfqueryparam value=SESSION.personid CFSQLType = "CF_SQL_INTEGER">, <cfqueryparam value='#nyear#' CFSQLType = "CF_SQL_INTEGER">, <cfqueryparam value='#nmonth#' CFSQLType = "CF_SQL_VARCHAR"> , <cfqueryparam value='#nDay#' CFSQLType = "CF_SQL_INTEGER">, '#nTime#', '#nEvent#', '#nEntryPrivacy#')
</CFQUERY>

But after all that, I get this error…
Lucee 5.2.6.60 Error (expression)
Message : cannot cast [SESSION.memberID] string to a number value

I never set SESSION.MemberID as a String, in fact it’s set as INT a number of times?
I’m stuck. Can anyone help me out of the Bog ?

PS - I “Starred” Lucee at GitHub (Star No. 443)

what do you see if you cfdump out the session variable?

1 Like

Looks like you not passing the session values in the queryparams. Try it this way.

Insert into entries (date, memberid,personid,year,month,day,time,event,entryprivacy) VALUES (Now(), <cfqueryparam value="#SESSION.memberID#" CFSQLType = "CF_SQL_INTEGER">, <cfqueryparam value="#SESSION.personid#" CFSQLType = "CF_SQL_INTEGER">, <cfqueryparam value='#nyear#' CFSQLType = "CF_SQL_INTEGER">, <cfqueryparam value='#nmonth#' CFSQLType = "CF_SQL_VARCHAR"> , <cfqueryparam value='#nDay#' CFSQLType = "CF_SQL_INTEGER">, '#nTime#', '#nEvent#', '#nEntryPrivacy#')
1 Like

CFDUMP shows the variable as a String

Mike,
That was it.
working now.
Thank you very much for the help !:+1:

By the way, I am pretty sure in lucee and possibly ACF you can remove a lot of the CF_SQL stuff and just do

<cfqueryparam value="#SESSION.personid#" sqltype = "INTEGER">