ASP / MS ACCESS检查用户名是否存在

问题描述

| 我正在用ASP创建我的第一个项目。该项目只是使用注册系统进行基本的登录/注销。我想知道如何解决以下代码,以便当用户注册到我的网站并输入数据库中已经存在的重复用户名时,它将重定向到仍填写所有字段但用户名字段为空的表单提示用户已经存在。 下面是我的代码
<%
Dim objShop
set objShop=Server.CreateObject(\"ADODB.Recordset\")

objShop.ActiveConnection=shop_STRING

objShop.source = \"SELECT * FROM Users WHERE UserName=\" & Request.Form(\"regUsername\")
objShop.CursorType=0
objShop.CursorLocation=2
objShop.LockType=3
objShop.Open

if not (objShop.EOF) then
    objShop.source=\"Users\"
    objShop.CursorType=0
    objShop.CursorLocation=2
    objShop.LockType=3
    objShop.Open

        objShop.Addnew
        objShop(\"FirstName\")= Request.Form(\"regFirst\")
        objShop(\"LastName\")= Request.Form(\"regLast\")
        objShop(\"StudentID\")= Request.Form(\"regID\")
        objShop(\"EmailAddress\")= Request.Form(\"regEmail\")
        objShop(\"UserName\")= Request.Form(\"regUsername\")
        objShop(\"Password\")= Request.Form(\"regPassword\")
        objShop(\"Address\")= Request.Form(\"regAddress\")
        objShop(\"Suburb\")= Request.Form(\"regSuburb\")
        objShop(\"Postcode\")= Request.Form(\"regPostcode\")
        objShop(\"ContactNumber\")= Request.Form(\"regContact\")
        objShop(\"CCCompany\")= Request.Form(\"regCCCompany\")
        objShop(\"CCNumber\")= Request.Form(\"regCCNumber\")
        objShop(\"CCExpiryMonth\")= Request.Form(\"regCCExpMonth\")
        objShop(\"CCExpiryYear\")= Request.Form(\"regExpYear\")
        objShop(\"CCCVCNumber\")= Request.Form(\"regCVCNumber\")
        objShop.Update

    objShop.Close
    set objShop= nothing
else
    response.write(\"Username already exists\")
end if
%>
我收到的代码错误是:
Microsoft JET Database Engine error \'80040e10\'

No value given for one or more required parameters.

/home/registration.asp,line 17 
所以我决定在添加值之前,再次将response.write(\“用户名已经存在\”)放入if语句中,然后出现此错误
Microsoft JET Database Engine error \'80040e14\'

Syntax error (missing operator) in query expression \'UserName=\'.

/home/registration.asp,line 17 
我不知道如何解决这个问题。任何帮助,将不胜感激!     

解决方法

        您需要在SQL表达式中的输入周围加上单引号
objShop.Source = \"SELECT * FROM Users WHERE UserName=\'\" & _
                    Request.Form(\"regUsername\") & \"\'\"
    ,        考虑您当前逻辑的此伪代码版本。
if not (objShop.EOF) then
    AddNew
Else
    display notice that user account already exists
如果您在User表中有一个或多个记录,其中UserName与regUsername匹配,则not(objShop.EOF)将为True。 所以你的意思是这样的:
If we have previously stored one or more records for this UserName 
    add another record for this UserName 
Else (no matching record exists)
    display notice that user account already exists
显然,您不应该收集和存储信用卡信息。     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...