Home arrow ASP arrow Page 5 - Make Revenue With Your Own Banner Management System
ASP

Make Revenue With Your Own Banner Management System


In this article Mitchell shows us how to develop a simple ad campaign and management system using ASP and an SQL Server database.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 33
November 01, 2001
TABLE OF CONTENTS:
  1. · Make Revenue With Your Own Banner Management System
  2. · Adding the banners
  3. · Saving the banners
  4. · The ASP to add the banner
  5. · The ASP to add the banner (contd)
  6. · Listing the banners
  7. · Deleting a banner
  8. · Displaying and tracking banners, impressions and click-thrus
  9. · The code in detail
  10. · Handling the banner clicks
  11. · Conclusion

print this article
SEARCH DEVARTICLES

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