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> |
Creating a Members Area in ASP
- Introduction
- Preparation
- Registration Form
- Registration Form (2)
- The register.asp Code
- The login form
- The members area
The register.asp Code
You might also like...
About the author
James Crowley
James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...
Interested in writing for us? Find out more.
ASP (3.0) books
-
Programming with Microsoft Visual Basic 2008
Programming with Microsoft Visual Basic 2008, Fourth Edition by the best-selling author, Diane Zak, is designed for a first course in programming. Using the most recent version of the software, Visual Basic 2008, this book teaches individuals how to ...
ASP (3.0) forum discussion
-
CorelDRAW VBA: cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline trace?
by dancemanj (0 replies)
-
client/server application using activex
by beautifulheart (0 replies)
-
problem with select within select
by hamidreza.hr923 (2 replies)
-
System Error &H8007007E. The specifed module could not be found.
by swiftsafe (5 replies)
-
How to get Hotmail Contacts
by salihagenter (5 replies)
ASP (3.0) podcasts
-
Stack Overflow Podcast: Podcast #45 – Keeping it Sharp
Published 7 years ago, running time 0h54m
Our guest this week is Eric Lippert – language architect extraordinaire and famous for all his work at Microsoft in developing their languages Eric joined Microsoft right out of college and was originally working on VB It’s time for everyone’s favorite game: Name the Worst Feature of that Microso.
Comments