经典ASP(VBScript)中的ElseIF语句

时间:2012-09-26 13:43:28

标签: asp-classic vbscript

这可能非常简单,但我几乎没有任何经典ASP语法的经验。基本上我有登录声明。如下所示:

<%if session("AccountID") = "0" or session("AccountID")=""  then%>
                    <%
                    If request.form("SmPress") = "Pressed" Then
                        dim SQLVerifyEmail
                        SQLVerifyEmail = "SELECT * FROM Users WHERE UserName= '"&killchars(request.form("UserName"))&"' and Password = '"&killchars(request.form("Password"))&"' AND Status = 'A' AND Deleted = 'no'  "
                        set RSVerifyEmail = MyConn.execute(SQLVerifyEmail)
                        If RSVerifyEmail.EOF Then

                            response.write ("<span class=loginerror>Incorrect login details.</span><br>")

                        Else
                            LastLogin2 = "UPDATE Users SET LastLogin = Convert(datetime,'"&now()&"',103) WHERE AccountID = '"&RSVerifyEmail("AccountID")&"' "
                            MyConn.execute(LastLogin2)
                            session("admin") = RSVerifyEmail("admin")
                            session("AccountID") = RSVerifyEmail("AccountID")
                            response.redirect "profile.asp"

                        End if
                    End if
                    %>

我想要做的就是拆分它,这样如果session = admin它会重定向到profile.asp,但如果它等于一个帐户ID,那么重定向到profile-user.asp。我尝试了以下但是通过大量错误:

ElseIF
                            LastLogin2 = "UPDATE Users SET LastLogin = Convert(datetime,'"&now()&"',103) WHERE AccountID = '"&RSVerifyEmail("AccountID")&"' "
                            MyConn.execute(LastLogin2)
                            session("admin") = RSVerifyEmail("admin") Then
                            response.redirect "profile.asp"

                        Else
                        session("AccountID") = RSVerifyEmail("AccountID")
                        response.redirect "profile-user.asp"
                        End if
                    End if
                    %>

我哪里错了?

1 个答案:

答案 0 :(得分:3)

假设您只在数据库的管理员资料中设置了RSVerifyEmail(“admin”)=“True”: 试一试:

<% if session("AccountID") = "0" or session("AccountID") = ""  then %>
<%
If request.form("SmPress") = "Pressed" Then
    dim SQLVerifyEmail
        SQLVerifyEmail = "SELECT * FROM Users WHERE UserName= '"&killchars(request.form("UserName"))&"' and Password = '"&killchars(request.form("Password"))&"' AND Status = 'A' AND Deleted = 'no'  "

    set RSVerifyEmail = MyConn.execute(SQLVerifyEmail)
        If RSVerifyEmail.EOF Then
            response.write ("<span class=loginerror>Incorrect login details.</span><br>")
        Else
            LastLogin2 = "UPDATE Users SET LastLogin = Convert(datetime,'"&now()&"',103) WHERE AccountID = '"&RSVerifyEmail("AccountID")&"' "
            MyConn.execute(LastLogin2)

            ' // Set only for admin session only for admins
            IF RSVerifyEmail("admin") = "True" Then
                RedirectWho         = "admin"
                session("admin")    = RSVerifyEmail("admin")
            Else
                RedirectWho         = "user"
            End if
            session("AccountID")    =   RSVerifyEmail("AccountID")
        End if
    set RSVerifyEmail = Nothing

    ' // redirect the logged in user or admin
    If RedirectWho = "admin" Then
        response.redirect "profile.asp"
    ElseIf RedirectWho = "user" Then
        response.redirect "profile-user.asp"
    End if
End if
%>