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

查看:129
本文介绍了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,回到原始页面新帐户并显示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重定向到谷歌,但它doesnt,我也有它显示在页面上是否我登录,所以我知道它是跳过cfelse之前的cflogin。

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天全站免登陆