Home arrow ASP arrow Page 3 - Hey... I Remember You!
ASP

Hey... I Remember You!


In my opinion, one of the most annoying things about some websites is logging in. Today, Mitchell will demonstrate how to create a nifty little feature that will allow your site to "remember" its visitors.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 45
November 15, 2001
TABLE OF CONTENTS:
  1. · Hey... I Remember You!
  2. · Storing the users login details
  3. · Adding new users
  4. · Creating the login page
  5. · The CheckLogin routine
  6. · The "remember me" part
  7. · Conclusion

print this article
SEARCH DEVARTICLES

Hey... I Remember You! - Adding new users
(Page 3 of 7 )

To add a new user, we will create a new ASP script named adduser.asp. Fire up notepad and enter the following code (Ignoring the line numbering):

<html>

<head>

<title> Add User </title>

</head>



<body bgcolor="#ffffff">

<form action="adduser.asp" method="post">

<input type="hidden" name="what" value="addnew">

<h1>Add New User</h1>

<pre>

Username: <input type="text" name="uname" maxlength="20">

Password: <input type="password" name="pass" maxlength="20">

<br><input type="submit" value="Add User">

</pre>

</form>

</body>

</html>


We've just created a pretty simple HTML form. A couple of things to note though: The form is posting the results to adduser.asp, which means that we are posting to the same script. We are also using a hidden input tag to set the value of a request variable named "what" to "addnew".

It's a common practice these days to post the results of a form back to the page that called it and distinguish what the page should display using hidden form variables. In our example above, the hidden "what" variable will be used to tell our script that we want to add a new user. To workout whether or not we are displaying the form to collect the users details, or actually adding the user to our database, we will use a select case statement. Add the following code to the top of your adduser.asp file.

1. <%

2.

3. dim strWhat

4. strWhat = Request.Form("what")

5.

6. select case strWhat

7. case "addnew"

8. ProcessUser()

9. case else

10. ShowUserForm()

11. end select

12.

13. sub ShowUserForm()

14. ...

...

34. end sub

35.

36. sub ProcessUser()

37.

38. dim objConn

39. dim strUserName

40. dim strPassword

41.

42. set objConn = Server.CreateObject("ADODB.Connection")

43. strUserName = Request.Form("uname")

44. strPassword = Request.Form("pass")

45.

46. objConn.Open "Provider=SQLOLEDB; Data Source=localhost; Initial Catalog=smartlogin; UId=sa; Pwd="

47.

48. objConn.Execute "INSERT INTO logins(user_name, password) VALUES('" & strUserName & "', '" & strPassWord & "')"

49.

50. Response.Write "New user " & strUserName & " added OK."

51.

52. end sub

53. %>


The code above splits our adduser.asp page into two sub routines. On line 4 we're setting the variable that will tell our script what to do. If a form is being posted, the Request.Form(“what”) key will contain the value “adduser”. If not, it will contain nothing, meaning that there is no form posted and that we should call our ShowUserForm sub that will display the form.

On the other hand, if the Request.Form(“what”) variable contains the value “adduser”, we will call the ProcessUser sub routine which uses an ADO connection object to connect to our database and execute an INSERT query. This INSERT query takes the username and password values from the form and inserts them into a new row in our logins table, thus creating a new user. Lastly, our ASP script simply prints out “New user John added OK.” (Assuming the name of the user we added was John).

Note that for simplicity, all error checking is omitted from the sample we're creating. Now that we can add users to our logins table, we will want to let the users login and “remember them”.
blog comments powered by Disqus
ASP ARTICLES

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials