ASP
  Home arrow ASP arrow Page 5 - Make Revenue With Your Own Banner Manageme...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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

Make Revenue With Your Own Banner Management System
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2001-11-01

    Table of Contents:
  • Make Revenue With Your Own Banner Management System
  • Adding the banners
  • Saving the banners
  • The ASP to add the banner
  • The ASP to add the banner (contd)
  • Listing the banners
  • Deleting a banner
  • Displaying and tracking banners, impressions and click-thrus
  • The code in detail
  • Handling the banner clicks
  • Conclusion

  • 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


    Make Revenue With Your Own Banner Management System - The ASP to add the banner (contd)


    (Page 5 of 11 )

    if objUpload.Files.Count = 0 then

    Response.Write "* Error ** You must select a file to upload. <a href='javascript:history.go(-1)'>Click here</a> to go back."

    Response.End

    end if

    strBanner_Image = objUpload.Files(1).ExtractFileName

    strBanner_Name = objUpload.Form.Item("banner_name").Value

    if strBanner_Name = "" then

    Response.Write "* Error ** You must enter a name for this banner. <a href='javascript:history.go(-1)'>Click here</a> to go back."

    Response.End

    end if

    if strBanner_Url = "" then

    Response.Write "* Error ** You must enter a url for this banner. <a href='javascript:history.go(-1)'>Click here</a> to go back."

    Response.End

    end if


    As with all good programs, scripts and components, we will include some basic error checking and handling procedures. In the first couple of lines, we will use our upload objects file collection property to check if a banner image has been uploaded. If one hasn't (if objUpload.Files.Count = 0) then we will show an error message and terminate the script.

    We will then get the image filename from the Files collection of our upload object and also the name and url that we typed in for this banner. Remember that we can't just access these using the Request.Form collection because we have set our forms enctype attribute to “multipart/form-data” and this blocks all access to the Request.Form collection when a page is processed. Instead, our upload component handles the variables parsed from the Request.Form collection for us, and stores them in its Form collection.

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

    objRS.Open "select * from banners", objConn, adOpenDynamic, adLockPessimistic


    The next part of our ASP script uses our database connection object (objConn) to connect to our database. If your database is not on the same machine as your ASP scripts, then change the Data Source=localhost attribute to match the name of your SQL Server.

    When we've connected to our database, we will open our recordset object (objRS). There are a number of ways to open a recordset object, but we will use the easiest one to keep this example simple. The first parameter, “select * from banners” can be any valid SQL query. It's just used to interact with the database for now. The next parameter, “objConn”, sets a reference to our database connection object, meaning that our recordset object will use objConn to execute its queries. Next, the “adOpenDynamic” cursor types tells SQL Server that we will want to have “dynamic” access to our database: both read and write, not just read, which is adOpenForwardOnly. The last parameter sets the lock type on our database.

    objRS.AddNew

    objRS("bannerName") = strBanner_Name

    objRS("bannerUrl") = strBanner_Url

    objRS("bannerImage") = strBanner_Image

    objRS("bannerImpressions") = 0

    objRS("bannerClickThrus") = 0

    objRS.Update


    The code above is the main part of our ASP script. This code tells SQL server that we want to add a new record to our database (objRS.AddNew). We then set the field name and value pairs that we want to add to our new record (bannerName, bannerUrl, bannerImage, bannerImpressions and bannerClickThrus) and call the Update method to save the record. Notice that we don't have to specify the values of the bannerId field because it is an auto-incrementing field.

    objRS.Close

    objConn.Close

    set objRS = nothing

    set objConn = nothing

    Response.Redirect "banners.asp"


    Lastly, we close the recordset and connection objects, set them to nothing (so the resources they used are freed up), and send a re-direct response code to our browser. See how the Response.Redirect command is telling our browser to go to banners.asp? This page doesn't exist, but will be used to show a list of all of the banners in our schedule. Now that we can add a banner, lets create the code to list our banners and also to delete banners when we no longer want them in our schedule.

    More ASP Articles
    More By Mitchell Harper


     

    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...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway