<%
'-- My server
Const DatabasePath = "c:/InetPub/wwwroot/mywebsite/fpdb/myAccessDatabase.mdb"
'-- My Web hosting company
'-- Const DatabasePath = "d:/mydomainname/fpdb/myAccessDatabase.mdb"
%>
<% Response.Buffer = true %>
<%
'-- Check if Submit button pushed, if not ignore the entire script
If Request.Form("btnAdd") = "Submit" Then
'-- Make sure all boxes have data entered into them
If Request.Form("name") <> "" OR Request.Form("password") <> "" OR _
Request.Form("password2") <> "" OR _
Request.Form("email") <> "" OR _
Request.Form("userID") <> "" Then
'-- Make sure the passwords match
If Request.Form("password") = Request.Form("password2") Then
'-- Declare your variables
Dim DataConnection, cmdDC, RecordSet, SQL, strError
Dim strUserName, strPassword, strEmail, strUserID
'-- Get data from the form fields
strUserName = Request.Form("name")
strPassword = Request.Form("password")
strEmail = Request.Form("email")
strUserID = Request.Form("userID")
'-- Create object and open database
Set DataConnection = Server.CreateObject("ADODB.Connection")
DataConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & DatabasePath & ";"
Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection
'-- default SQL
SQL = "SELECT * FROM tblSecurity"
If Request.Form("name") <> "" Then
SQL = "SELECT tblSecurity.* FROM tblSecurity WHERE " & _
"tblSecurity.userID='" & strUserID & "' AND " & _
"tblSecurity.password ='" & strPassword & _
"' OR tblSecurity.email ='" & strEmail & "'"
End If
cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.Recordset")
'-- Cursor Type, Lock Type
'-- ForwardOnly 0 - ReadOnly 1
'-- KeySet 1 - Pessimistic 2
'-- Dynamic 2 - Optimistic 3
'-- Static 3 - BatchOptimistic 4
RecordSet.Open cmdDC, , 0, 2
'-- check to see if the user and password or
' e-mail address have registered before
If Not RecordSet.EOF Then
If RecordSet.fields("email")=strEmail Then
strError = "" & _
"Sorry this email has already been " & _
"registred, please try again" & _
""
Else
'Redo page and say that this User name
'and Password are already taken
strError = "" & _
"Sorry this user name and password are " & _
"already taken, please try again" & _
""
End If
Else
'-- Add new record to the database
Dim Dconn, sSQL
Set Dconn = Server.CreateObject("ADODB.Connection")
Dconn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
DatabasePath & ";"
sSQL = "INSERT INTO tblSecurity(name, email, userID, " & _
"password, userLevel) VALUES ('" & strUserName & _
"','" & strEmail & "','" & strUserID & _
"','" & strPassword & "',1)"
Dconn.Execute sSQL
Dconn.Close
Set Dconn = Nothing
'Forward the user to page to notify of authentication
Response.Redirect "youokman.asp"
End If
Else
strError = "Your passwords don't match"
End If
'-- Close all connections
RecordSet.Close
Set RecordSet = Nothing
DataConnection.Close
Set DataConnection = Nothing
Else
'Tell them what they entered wrong
strError = "Please fill in all the boxes"
End If
End If
%>
New Page 1
<%
'-- Error message if there is any
Response.write (strError & "
")
%>