经典ASP&访问DB - FROM子句错误

时间:2015-05-30 13:07:28

标签: ms-access vbscript asp-classic

这是我第一次在这里发帖,希望每个人都能理解我的英语,我正在尝试使用CSS和一些Ajax / Jquery在VBScript(经典ASP)中创建基于MS Access的站点。

我已经到了管理登录和管理的重点。会话,所以在主页面中创建了一个弹出窗体,并将子目录数据创建到另一个asp页面以验证用户并最终打开会话,这只是一个问题:FROM子句有错误,我实际尝试了数据库上的相同查询,它确实有效!

我的大多数代码都是意大利语用于演示目的: “nome”=姓名,“cognome”=姓氏,“DataNascita”=生日,“amministratore”=管理员。

对于DB,名称因表而异,因为我尝试编写不同名称的外键以排除每个选项。

HTML表格代码:

<form Action="authenticate.asp" Method="Post">
                    <div class="row">
                        <div class="cells"> 
                            <span> Username </span> 
                        </div>
                        <div class="celld">
                            <Input Type="Text" Name="TxtUsername" Placeholder="Username"> 
                        </div>
                    </div>
                    <div class="row">
                        <div class="cells"> 
                            <span> Password </span>
                        </div>
                        <div class="celld">
                            <Input Type="Password" Name="TxtPassword" Placeholder="Password">  
                        </div>
                    </div>
                    <div class="row">
                        <div class="cellrowspan"> 
                            <Input Type="Submit" Value="Login"> 
                        </div>
                    </div>
                </form>

不能张贴图像,因为这是我的数据库的结构

Table (Account) - AccountID (Pk) [Auto.Inc], Username [String], Password [String]

Table (User) - UserID (Pk) [Auto.Inc], ProfiloID (Fk. of Account) [Long Integer], Nome [String], Cognome [String], Data_Nascita [Data], E_Mail [String], LivelloID (Fk. of Livello) [Long Integer].

Table (Livello) - PrivilegioID (Pk) [Auto.Inc], Categoria [String]

最后,对表格的回复中的authenticate.asp页面

<%
Dim Username, Password, Nome, Cognome, DataNascita, Email, IDLevel, StrConn, Conn, Rs
    Username = Trim(Request.Form("TxtUsername"))
    Password = Trim(Request.Form("TxtPassword"))

    IF Username <> "" AND Password <> "" THEN
        StrConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Server.MapPath("Users.accdb")

        Set Conn = Server.CreateObject("ADODB.Connection")
        Set Rs = Server.CreateObject("ADODB.Recordset")

        Conn.Open StrConn
        Set Rs = Conn.Execute ("SELECT User.Nome, User.Cognome, User.Data_Nascita, User.E_Mail, User.LivelloID FROM (Account INNER JOIN User ON Account.AccountID=User.ProfiloID) INNER JOIN Livello ON User.LivelloID=Livello.PrivilegioID WHERE Account.Username='" & Username & "' AND Account.Password='" & Password & "'")
            Nome = Rs.Fields("Nome")
            Cognome = Rs.Fields("Cognome")
            DataNascita = Rs.Fields("Data_Nascita")
            Email = Rs.Fields("E_Mail")
            IDLevel = Rs.Fields("LivelloID")

        Rs.Close
        Conn.Close
        Set Rs = Nothing
        Set Conn = Nothing

        Session("NomeUtente") = Nome
        Session("CognomeUtente") = Cognome
        Session("DataNascita") = DataNascita
        Session("Email") = Email
        Session("Authenticated") = 1
        IF IDLevel = 1 THEN 
            Session("Amministratore") = "True"
        ELSE 
            Session("Amministratore") = "False"
        END IF
    END IF

Response.Redirect ("homepage.asp")
%>

1 个答案:

答案 0 :(得分:1)

您使用了很多保留字来访问字段名称。如果你在内部进行查询访问系统运行相同,但如果你使用asp传递查询将会出错。您应该更改表字段的名称。

Es。:表“user”变成了“utenti”等......

相关问题