Welcome to the Final Part of our tutorial...
That is the
create.asp page where we will create a page to add new user to be able to use this system to access to the protected content/success.
asp page.
Let us begin..
- Code: Select all
<%
'Assign entered username, password and fullname into a variable
Username = Request.Form("txtUsername")
Password = Request.Form("txtPassword")
Fullname = Request.Form("txtFullname")
'Check if all of the textfield is not empty when submitting the create new user form!
'If one of them is empty, alert user with QueryString!
If Username = "" or Password = "" or Fullname = "" Then
Response.redirect("login.asp?login=createuserfailed")
End If
'MySQL Database connection to retrieve all the user information from the database!
'This database connection is different from my previous tutorial since we are performing add record and update function to the database.
'The database must be able to accept any update statement by the sql command.
Dim connectionString,rs
connectionString= "DRIVER={MySQL ODBC 3.51 Driver}; SERVER = localhost; DATABASE=mydatabase; UID=root; PASSWORD=mypassword;"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM userlogin", connectionString, 1, 3 'This connection are able to accept update statement!
'Check for duplicated entry for the Username and Fullname entered by the user in the registration form!
do while not rs.EOF
'If Username already exist, alert user with QueryString!
if rs("username")=Username then
set rs=nothing
set conn=nothing
Response.Redirect("login.asp?login=createnamefailed")
'If Fullname already exist, alert user with QueryString!
Else If rs("fullname")=Fullname Then
set rs=nothing
set conn=nothing
Response.Redirect("login.asp?login=createfullnamefailed")
End If
rs.MoveNext
loop
'If everything is OK, no duplication of username, fullname or whatsoever,
'Add the new user info record into the database!
rs.AddNew
'Insert the value captured earlier at the top of this page:
'Username = Request.Form("txtUsername"),
'Password = Request.Form("txtPassword") and
'Fullname = Request.Form("txtFullname") and put it into the database!
rs("username")=Username
rs("password")=Password
rs("fullname")=Fullname
'Save record in the database
rs.Update
'Close the database connection!
set rs=nothing
set conn=nothing
'Redirect the user to the greeting page where they can login for the first time!
Response.Redirect("login.asp?login=createnewsuccess")
%>
Finally, this tutorial has come to it's end!
I hope this tutorial will make someone getting new experience and knowledge on
asp and hopefully we will help each other soon
[ You can see ASP Login Example Page here! ]
If any of you having problem with this tutorial, please let me know by Private Message me at this [Link]
Thank You Webforumz!
Have a nice day with
<%ASP%>