Coldfusion 8 同时执行 CFIf 和 CFElse 语句 [英] Coldfusion 8 doing both CFIf and the CFElse statement

查看:10
本文介绍了Coldfusion 8 同时执行 CFIf 和 CFElse 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为电子商务网站制作用户注册应用程序,但遇到了一个非常奇怪的问题.当我运行这段代码时:

I am making a user signup app for an ecomerce site, but I have run into a very odd problem. When I run this code:

<cfif isValid("email", form.email)>
    <cfquery name="check_user" datasource="#request.dsn#">
        SELECT var_username, var_password
        FROM tbl_users
        WHERE var_username = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FORM.EMAIL#"> 
        AND var_password = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FORM.PASSWORD#"> 
    </cfquery>
    <cfif check_user.recordcount LT 1>
        <cfquery datasource="#request.dsn#" name="insertuser">
            INSERT INTO tbl_users (var_username, var_password) 
            VALUES
            (<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FORM.EMAIL#">,
            <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FORM.PASSWORD#">)
        </cfquery>


        <cflogin idletimeout="1800">
        <cfloginuser 
                name = "#FORM.email#"
                password ="#FORM.password#"
                roles = "0">

        </cflogin>
        <cflocation addtoken="No" url="#request.secure_url#checkout.cfm">
    <cfelse>
        <cfset client.error_message = "Your Email Address is already registered.">
        <cflocation addtoken="No" url="#request.site_url#New-Account.html">
    </cfif>

<cfelse>
    <cfset client.error_message = "Your Email Address is not Valid.">
    <cflocation addtoken="No" url="#request.site_url#New-Account.html">

</cfif>

这段代码应该做的是检查电子邮件是否已经在数据库中,如果没有,则将电子邮件/密码添加到数据库中,然后将它们登录并将它们移动到安全结帐站点.代码实际上在做什么,但完全不同.它正在检查它们是否在数据库中,然后添加它们,但是,在将它们添加到数据库后,它会跳过登录和 cflocation 并转到 cfelse,返回原始页面New-Account"并显示 client.error_message.

What this code is supposed to do, is check to see if the email is already in the database, if its not, it then adds the email/password into the database then logs them in and moves them to the secure checkout site. What the code is actually doing, is quite different though. It is checking to see if they are in the database, and then adding them, however, after it adds them to the database it skips the login and the cflocation and goes to the cfelse, going back to the original page "New-Account" and displaying the client.error_message.

代码如何运行 cfif check_user.recordcount,然后通过它的一部分跳到 cfelse?

How is it possible for the code to run the cfif check_user.recordcount and then part way through it skip to the cfelse?

我已经做了一些尝试缩小发生的事情的范围-

Things I have done to try and narrow down whats happening-

它正在通过 check_user 语句并添加用户,因为我可以直接访问数据库并且在尝试注册用户后,我将其删除并重试(请注意,当我尝试创建它时,它确实创建它),所以我知道它通过了 insertuser cfquery.我已将cflocation更改为重定向到google,但它没有,并且无论我是否登录,它都会显示在页面上,所以我知道它在cflogin之前跳到cfelse.

It is getting pass the check_user statement and adding a user, because I have direct access to the database and after trying to signup a user, I delete it and try again (and notice that when I try to create it, it does create it), so I know its getting past the insertuser cfquery. I have changed the cflocation to redirect to google, but it doesnt, and I also have it show on the page whether or not I am logged in, so I know that it is skipping to the cfelse before the cflogin.

推荐答案

我建议暂时注释掉你所有的 cflocations,看看你的行为是否相同.可能是您的登录过程在您的 cflocation 开始之前没有完成.

I would suggest commenting out all of your cflocations temporarily and seeing if your behaviour is the same. It could be that your login process doesn't finish before your cflocation starts.

或者,可能是您的页面第一次正确提交给自己,然后第二次点击 else 子句.

Or, it could be that your page submits to itself correctly the first time, and then the second time hits the else clause.

你的代码中没有什么对我来说显然是错误的.

There is nothing in your code that is obviously wrong to me.

这篇关于Coldfusion 8 同时执行 CFIf 和 CFElse 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆