View Single Post
  #5 (permalink)  
Old Oct 25th, 2007, 05:43
Monie Monie is offline
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Send a message via Yahoo to Monie
Re: ASP-MySQL: Advance Login Page [Final Part: Register New User]

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%>
Attached Files
File Type: zip ASP_MySQL_Login.zip (5.5 KB, 73 views)

Last edited by Monie; Nov 5th, 2007 at 02:31.