简体   繁体   English

Coldfusion和会话变量未设置

[英]Coldfusion and session variable not setting

I have a survey form with 5 ques, there is one question on each page and user clicks through them with next button on the page. 我有一个包含5个问题的调查表,每页上有一个问题,用户单击页面上的下一个按钮即可将其单击。 Now, the user is not logged in, I want to set a session variable only when the user takes the first ques on form and clicks next. 现在,用户尚未登录,我只想在用户接受表单上的第一个问题并单击下一步时才设置会话变量。 But I am getting userid not defined in session for the line 2. I am not really sure what I am doing wrong here. 但是我在第2行的会话中未定义用户ID。我不确定在这里我做错了什么。 Can anyone suggest if they see what is going on. 任何人都可以建议他们是否看到正在发生的事情。 I don't want to be creating multiple userids every time he hits next button. 我不想每次他按下下一步按钮时都创建多个用户ID。 Thanks 谢谢

<cfif structKeyExists(FORM, "user_mode") and form.user_mode EQ "next">  

<cfif NOT ( StructKeyExists(session,userid) )> 
<cfquery name="insertuser" datasource="#application.datasource#">
         INSERT INTO survey_user(ip_address)
            VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#CGI.REMOTE_ADDR#" />)
        </cfquery>
</cfif>
</cfif>
StructKeyExists(session,userid)

should be: 应该:

structKeyExists( session, 'userid' )

Note the quotes. 注意引号。 Without them it's looking for the variable "userid" rather than the key name "userid". 没有它们,它将寻找变量“ userid”而不是键名“ userid”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM