Forums

This topic is locked

if user exists (Asp)

Posted 19 Jun 2002 19:06:40
1
has voted
19 Jun 2002 19:06:40 James Smith posted:
hey ive designed a registration page, but i want to know how to make it check if a user exists or not and if a user does then go to a different page. how can i do this. the code of my page is bellow

<%@LANGUAGE="VBSCRIPT"%>
<%
set oConn = Server.CreateObject("ADODB.Connection"
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\goftr\db\members2000.mdb")
%>
<%
Dim rsCheckDuplicates__strUserID
rsCheckDuplicates__strUserID = "xyz"
if (Request.Form("loginanme" <> "" then rsCheckDuplicates__strUserID = Request.Form("loginanme"
%>
<%
set rsCheckDuplicates = Server.CreateObject("ADODB.Recordset"
rsCheckDuplicates.ActiveConnection = oConn
rsCheckDuplicates.Source = "SELECT * FROM tblUser WHERE loginname = '" + Replace(rsCheckDuplicates__strUserID, "'", "''" + "'"
rsCheckDuplicates.CursorType = 0
rsCheckDuplicates.CursorLocation = 2
rsCheckDuplicates.LockType = 3
rsCheckDuplicates.Open()
rsCheckDuplicates_numRows = 0
%>
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert") <> "" Then

MM_editConnection = oConn
MM_editTable = "tblUser"
MM_editRedirectUrl = ""
MM_fieldsStr = "loginname|value|password|value|affiliation|value"
MM_columnsStr = "loginname|',none,''|password|',none,''|affiliation|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
if not rsCheckDuplicates.EOF then
response.redirect ("register.asp"
else
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert") <> "" Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),","
Delim = MM_typeArray(0)
If (Delim = "none" Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none" Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none" Then EmptyVal = ""
If (FormVal = "" Then
FormVal = EmptyVal
Else
If (AltVal <> "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
end if
%>
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><i><font face="Arial, Helvetica, sans-serif" size="+2">Welocme
to the Golden age of the Republic</font></i></p>
<hr>
<p align="left"> </p>
<div align="center">
<p>To gain full acces to our site you will need to register. No personal information
will be collected abd your login information</p>
<p>will simply be used to ensure that only registered memebrs use our services.
Thank you. To reset the form at any time press</p>
<p>the reset button located at the bottom.</p>
<p> </p>
<hr>
<form name="form1" method="POST" action="<%=MM_editAction%>">
<div align="left">
<p>User Name
<input type="text" name="loginname">
*</p>
<p>Password
<input type="password" name="password">
*</p>
<p>Affiliation
<select name="affiliation">
<option value="Sith">Sith</option>
<option value="Republic">Republic</option>
</select>
*</p>
<p>* denotes a required field</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input type="reset" name="reset" value="Reset">
</p>
</div>
<input type="hidden" name="MM_insert" value="true">
</form>
<p align="left"> </p>
</div>
</body>
</html>
<%
rsCheckDuplicates.Close()
%>

Replies

Replied 25 Jun 2002 04:38:34
25 Jun 2002 04:38:34 Kelly Brady replied:
Dude there is already a built in function in UD4 and DMX Its listed under Server Behaviors ---> Authentication ---> Check new user. Or you could right it by hand however it looks like you are checking to see if there are duplicates. You know some times UD and DMX create way to much code try this.

Create a form page:
<form name=login method=post action=processpage.asp>
<input type=text name=username>
<input type=text name=password>
<input name="submit" type="submit">
</form>


processpage.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Dim conn
Dim SQLcheck
Dim SQLInsert
Dim rsCheck
Dim username = Request("username"
Dim password = Request("password"

Set conn = Server.CreateObject("ADODB.Connection"

conn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\goftr\db\members2000.mdb")

SQLcheck= "SELECT * FROM tblUser WHERE username = '" + Replace(username, "'", "''" "'"

Set rsCheck= conn.Execute(SQLcheck)
%>
<% ' Create Redirect if users exists
If Not rsCheck.EOF Or Not rsCheck.BOF Then
Response.Redirect("userexists.asp"
Else
Response.Write"This user has been added to the db."

' Now lets add user to the db

SQLInsert = "INSERT INTO tblUser
SET username = '" + Replace(username, "'", "''" "', password = '" + Replace(password, "'", "''" "'"
End If
%>

You should clean it up bu closing your rs's but hey look its only 29 lines of code as apposed to 174

Hope this helps!

Replied 25 Jun 2002 04:42:01
25 Jun 2002 04:42:01 Kelly Brady replied:
I forgot to things in that code the + sign after the replace. Just replace this code from the first one. Sorry:

Create a form page:
<form name=login method=post action=processpage.asp>
<input type=text name=username>
<input type=text name=password>
<input name="submit" type="submit">
</form>


processpage.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Dim conn
Dim SQLcheck
Dim SQLInsert
Dim rsCheck
Dim username = Request("username"
Dim password = Request("password"

Set conn = Server.CreateObject("ADODB.Connection"

conn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\goftr\db\members2000.mdb")

SQLcheck= "SELECT * FROM tblUser WHERE username = '" + Replace(username, "'", "''" + "'"

Set rsCheck= conn.Execute(SQLcheck)
%>
<% ' Create Redirect if users exists
If Not rsCheck.EOF Or Not rsCheck.BOF Then
Response.Redirect("userexists.asp"
Else
Response.Write"This user has been added to the db."

' Now lets add user to the db

SQLInsert = "INSERT INTO tblUser
SET username = '" + Replace(username, "'", "''" "', password = '" + Replace(password, "'", "''" + "'"
End If
%>

Replied 25 Jun 2002 05:21:45
25 Jun 2002 05:21:45 Kelly Brady replied:
OK my brain is way fried use this for your INSERT, I guess I would have gotten it right if I had used the INSERT script built in huh. Im kicking myself right now.

' Now lets add user to the db

<%
SQLInsert = "INSERT INTO tblUser
(username, password)
VALUES ('" + Replace(username, "'", "''" + "','" + Replace(password, "'", "''" + "'"
%>


Reply to this topic