Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Re: [access_asp]


Message #1 by syed moiz <sa_moiz@y...> on Sun, 22 Sep 2002 22:24:34 -0700 (PDT)
Hai ,

my task was to create a registration form which must
register new users and check whether the username and
email are already registered or not,
if they are registered already error messages will be
given to user redirecting back to the same file.
but this code is refreshing form whenever a username
is found in the database.
i,e the user is taken back to the newuser.asp with a
fresh form, and he has to enter all the details from
field to last.
cant i have some thing that can give him the option to
enter new username and emailid with the details of
other fields displayed in the form.
thanx
<%Response.Buffer="true"%>
<!--#include file="conn.inc"-->
<!--#include file="adovbs.inc"-->

<% 
'Declare our variables
Dim username, password, duplicate, objConn, objRS

'Test our variables to make sure we're not entering
empty strings
username=trim(request.form("requireduname"))
password=trim(request.form("requiredpwd"))
emails=trim(request.form("requiredemail"))
duplicate=false 

set objConn=Server.CreateObject("ADODB.Connection")
objConn.Open ( myConnStr)
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "newusersinfo", objConn , ,
adLockOptimistic, adCmdTable 
Do While Not (objRS.EOF OR duplicate) If
(StrComp(objRS("username"), username, vbTextCompare) 
0) Then 
response.redirect "newuser.asp?error=1"
ElseIf (StrComp(objRS("Emailid"), emails,
vbTextCompare) = 0) Then 
response.redirect "newuser.asp?error=2"
End If

objRS.MoveNext
Loop 

objRS.AddNew

objRS.Fields("Username") = username
objRS.Fields("Password") = password
objRS.Fields("FirstName")=request("requiredfname")
objRS.Fields("LastName")=request("requiredlname")
objRS.Fields("Emailid")=emails
objRS.Fields("JobTitle")=request("requiredjtitle")
objRS.Fields("Division")=request("requireddvsn")
objRS.Fields("Department")=request("requireddpt")
objRS.Fields("DOJ")=request("requireddoj")

objRS.Update
objRS.Close
Set objRS = nothing
objConn.Close
Set objConn = nothing

%><html><head>
</head>
<body>
<table width="100%" border="0" height="57">
  <tr> 
    <td height="60"><img src="gifimages/innlogo.gif"
width="400" height="61"></td>
  </tr>
</table>
<table width="100%" border="0">
  <tr> 
    <td width="17%" height="20">&nbsp;</td>
    <td width="64%" height="20">
      <div align="center"><font face="Verdana, Arial,
Helvetica, sans-serif" size="2"
color="#000000"><b>Registration 
        Confirmation</b></font></div>
    </td>
    <td width="19%" height="20">&nbsp;</td>
  </tr>
</table>
<table width="100%" border="0">
  <tr>
    <td><%response.write "Congratulations,
registration sucessfully completed and your log in
details are"%></td>
  </tr>
</table>
<table width="100%" border="0">
  <tr>
    <td width="15%"><font size="2" face="Verdana,
Arial, Helvetica, sans-serif"><b>Username 
      </b></font></td>
    <td width="85%"> <b><font color="#0033CC" size="2"
face="Verdana, Arial, Helvetica,
sans-serif"><%=request("requireduname")%>&nbsp&nbsp</font><font
color="f47c20" size="2" face="Verdana, Arial,
Helvetica, sans-serif">&nbsp 
      </font></b></td>
  </tr>
  <tr>
    <td width="15%"><font size="2" face="Verdana,
Arial, Helvetica, sans-serif"><b>Password 
      </b></font></td>
    <td width="85%"><font color="#0033CC" size="2"
face="Verdana, Arial, Helvetica,
sans-serif"><%=request("requiredpwd")%></font></td>
  </tr>
</table>
<p>&nbsp;</p>
<font face="Courier New, Courier, mono"
size="2"><b><font size="3" color="#000000"><a
href="default.asp"><font face="Verdana, Arial,
Helvetica, sans-serif" size="2">Click 
Here to Sign In</font></a></font></b></font> 
<p>&nbsp;</p>

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 23 Sep 2002 15:50:59 +1000
Post the form to itself.
www.adopenstatic.com/resources/code/UIValidation.asp
has the general format of what you want to do.

Here are some important tips:
a) DO NOT compare the new username to existing users using the method you
are using. It is not scalable whatsoever! Use an SQL statement instead, eg:

<%
strSQL = _
    "SELECT NULL FROM NewUsersInfo " & _
    "WHERE UserName = '" & UserName & "' " & _
    "OR EmailID = '" & Emails & "'"

objRS.Open strSQL, objConn

If objRS.EOF then
    ' Username and password is unique
Else
    ' Either username or email is duplicated
End If
%>

This just returns a single result, not the entire table, and you don't end
up looping through an entire table. Remember, databases work on *set*
theory. DO NOT use cursors if you can avoid it.

b) Do not use recordsets to enter/update/delete data. Use an SQL Statement
instead. Recordsets are for retrieving data from a datasource.

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "syed moiz" <sa_moiz@y...>
Subject: [access_asp] Re: [access_asp]


: Hai ,
:
: my task was to create a registration form which must
: register new users and check whether the username and
: email are already registered or not,
: if they are registered already error messages will be
: given to user redirecting back to the same file.
: but this code is refreshing form whenever a username
: is found in the database.
: i,e the user is taken back to the newuser.asp with a
: fresh form, and he has to enter all the details from
: field to last.
: cant i have some thing that can give him the option to
: enter new username and emailid with the details of
: other fields displayed in the form.
: thanx
: <%Response.Buffer="true"%>
: <!--#include file="conn.inc"-->
: <!--#include file="adovbs.inc"-->



  Return to Index