We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 95,009 times

Contents

Related Categories

Creating a Members Area in ASP - The register.asp Code

The register.asp Code

register.asp

<%
Option Explicit
Dim strError, strSQL
'see if the form has been submitted
If Request.Form("action")="register" Then
   'the form has been submitted

   '// validate the form

   'check if a username has been entered
   If Request.Form("username") = "" Then _
       strError = strError & "- Please enter a username<br>" & vbNewLine

   'check if a password has been entered
   If Request.Form("password") = "" Then _
       strError = strError & "- Please enter a password<br>" & vbNewLine 

   'check if the passwords are the same... but don't display it if the password field is blank.
   If Request.Form("password") <> Request.Form("password_confirm") _
       And Request.Form("password") <> "" Then _
           strError = strError & "- Your passwords do not match<br>" & vbNewLine
   '// check if an error has occured
   If strError = "" Then
      'continue
      'include database connection code
      %>
      <!--#include file="inc-dbconnection.asp"-->
      <%
      On Error Resume Next

      '// create the SQL
      strSQL = "INSERT INTO members ([username],[password]) VALUES " & _
         "('" & fixQuotes(Request.Form("username")) & "','" & _
         fixQuotes(Request.Form("password")) & "')"
      '// run the SQL
      objConn.Execute strSQL
      '// check for an error
      '// ATTENTION: this should be changed depending on the database provider
      If Err.Number = -2147467259 Then
          strError = "- That username is already in use. Please choose another<br>" & vbNewLine
      ElseIf Err.Number <> 0 Then
          strError = "- An error occured. " & Err.Number & " : " & _
              Err.Description & "<br>" & vbNewLine 
      Else
          'record created... redirect
          Response.Redirect "login.asp?msg=" & Server.URLEncode("Thank you for registering")
          Response.End
      End If

      'restore standard error handling
      On Error Goto 0 

   End If
   If strError <> "" Then
      'output the error message
      'add extra HTML...
      strError = "<p><font color=""#FF0000"">The following errors occured:" & _
         "</font><br>" & vbNewLine & strError
   End If
End If

Function fixQuotes(strData)
  fixQuotes = Replace(strData,"'","''")
End Function
%> 
<html>
<head> 
<title>My Website's Registration Page</title>
</head> 
<body>
<h1>Member Registration</h1>
<p>Please fill out the following form to register as a member, and
 gain access to our members area.</p>
<%=strError%>
<form action="register.asp" method="POST">
<input type="hidden" name="action" value="register">
<table border="0">
<tr>
  <td><b>Username</b></td>
  <td><input type="text" maxlength=20 name="username"
 value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td>
</tr>
<tr>
  <td><b>Password</b></td>
  <td><input type="password" maxlength=20 name="password"
 value="<%=Server.HTMLEncode(Request.Form("password"))%>"></td>
</tr>
<tr>
  <td><b>Password Confirm</b></td>
  <td><input type="password" maxlength=20 name="password_confirm"
 value="<%=Server.HTMLEncode(Request.Form("password_confirm"))%>"></td>
</tr>
<tr>
  <td> </td>
  <td><input type="submit" value="Complete Registration"></td>
</tr>
</table>
</form> 
</body>
</html>

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [1744] Creating a Members Area in ASP

    Posted by shawne on 11 May 2007

    I want to with u a happy day .. And thank's once again for giving us the source code.. but unfortunately i just use your code for my following project but then i got some error said ---The include ...

  • Re: [1744] Creating a Members Area in ASP

    Posted by rob1210 on 15 Feb 2007

    Hi, being a bit of a newbee to ASP but am quite up to speed with SQL and some web development. I am struggling a little with getting to grips with what I need to do with some of the code. In the tutor...

  • Re: registration form

    Posted by nathancan on 20 Nov 2006

    If I look at the page in Dreamweaver or similar I also see the code.  However, when it is uploaded to my web server it appears without the code.
    Are you sure your web server can run asp?

  • Re: [1744] Creating a Members Area in ASP

    Posted by nathancan on 20 Nov 2006

    Hi there
    I'm new to asp and thought i'd start applyinh what I've been reading by using this tutorial. When I attempt to use login.asp or register.asp I receive the following error:

  • Re: [1744] Creating a Members Area in ASP

    Posted by coolcalimba on 18 Jun 2006

    Hi, I've never used ASP before and just want to create a members area where I can view the members and their attributes in a simple non-relational database, for my website that is being updated (fr...