我正在使用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
所以我决定在添加值之前在if语句中再次添加response.write(“Username already exists”),然后出现此错误:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'UserName='.
/home/registration.asp, line 17
我不知道如何纠正这个问题。任何帮助将不胜感激!
答案 0 :(得分:1)
您需要在SQL表达式中输入单引号
objShop.Source = "SELECT * FROM Users WHERE UserName='" & _
Request.Form("regUsername") & "'"
答案 1 :(得分:1)
考虑当前逻辑的伪代码版本。
if not (objShop.EOF) then
AddNew
Else
display notice that user account already exists
如果UserName中的一个或多个记录与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
显然,您不应该收集和存储信用卡信息。