ASP
  Home arrow ASP arrow Page 4 - Writing Your First ASP Application ( Quick...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Writing Your First ASP Application ( Quick Start )
By: Rich Smith
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 82
    2003-08-06

    Table of Contents:
  • Writing Your First ASP Application ( Quick Start )
  • Users On Your Website
  • Dissecting The Needs For The Application
  • Login Page
  • Showing The List Of Users
  • Simplifying The Code
  • Removing Users From The List
  • Additional Enhancements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Writing Your First ASP Application ( Quick Start ) - Login Page


    (Page 4 of 8 )

    Before we can create the login page, we will need the database in which to keep our names. One of the easiest databases to work with is Microsoft Access. For our example, we will assume that I have created a database called “UserBase”. In this database, I have a table named “UsersOnline”, with one column named “UserName”. For ease of discussion, I have kept this database very simple, but more tables and columns could be added to add more functionality to the application. I have also created a DSN called “UserDSN” to make connectivity to the database simple. I will not go into the details of database connectivity in this article.

    Now that I have a database, I need to create a login page. This could be a page by itself, or just a textbox and button within an even larger web page. Here is the code for our login page.

    login.asp:

     Please enter your name to login
    <
    FORM action=/dologin.asp” method=”post”><INPUT name=username> <INPUT type=submit value=Submit name=B1> </FORM>

    When the user types in their name and clicks the submit button, that information will be passed to the dologin.asp page. This program’s job will be to take the name that was entered and manually add it to the table.

    dologin.asp:

     <%@ LANGUAGE="VBSCRIPT" %><%

    dim conn
    dim strsql
    dim username

    ‘ Read the username from the form data
    username 
    trim(request.form("UserName"))

    ‘ Create a session variable that contains the user name
    Session
    (“UserName”) = username

    ‘ Create a SQL statement to insert the name into our table
    strsql 
    "insert into UsersOnline (Username) values (“ & chr(39) & username & chr(39) & “)”

    ‘ Open the database using our DSN
    strconn = “DSN=UserBase”

    set conn = server.createobject("
    adodb.connection")
    conn.open strconn

    ‘ Execute the SQL Statement to insert the record
    conn.execute strsql

    ‘ Close the database connection

    conn.close
    set conn = nothing

    %>Login Successful You have successfully logged in to our system. 

    There are a few things I would like to point out at this point. First, you will notice that all of the VBScript code is contained within <% and %> delimiters. All VBScript must be within these delimiters or the ASP page will not load. I also used the function chr(39) to represent a quotation mark inside the SQL statement.

    Next, you will notice that I did not use any error checking. For readability purposes, I have kept the code as clean and simple as possible. For a real-world scenario, appropriate error handling and checking would be applied.

    I also made use of a session variable to save the username. Each unique user to the website is assigned a session, and each variable you set within the session is unique to that user only. So if five people logged in with different names, each would have his or her own session Ids.

    Finally, I am using ADO to connect to the database. Using ADO for database access is a whole topic unto itself, and I will not go into great detail about it here in this article.

    More ASP Articles
    More By Rich Smith


     

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT