我正在用ASP創建我的第一個項目。這個項目只是使用註冊系統進行基本的登錄/註銷。我想知道如何修正下面的代碼,以便當用戶註冊到我的網站並輸入已經存在於我的數據庫中的重複用戶名時,它將重定向到所有字段仍填寫完畢但用戶名字段爲空的表單給出用戶已經存在的消息。ASP/MS訪問檢查,看看用戶名是否存在
下面是我的代碼:
<%
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(「用戶名已經存在」)如果聲明之前添加的值,然後出現此錯誤:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'UserName='.
/home/registration.asp, line 17
我不知道我會怎麼corr解決這個問題。任何幫助,將不勝感激!
[SQL注入操場..](http://en.wikipedia.org/wiki/SQL_injection)在'objShop.Source = ...' – 2011-05-30 12:54:16