Article

Create your own Banner Management Application

Page: 1 2 3 4 5 6 7 Next

Deleting a banner:

No doubt, you’ll be curious as to how to go about deleting a banner from your rotation, right? To delete a banner, we will create a new page called delbanner.asp. Once you've created the page, you can click on the [ Delete ] link that's shown on the "Current Banners in Rotation" page to remove a banner from the list. Create a new page called delbanner.asp and add this code to it:

<%@ Language="VBScript" %>    
<%    
 dim objConn    
 set objConn = Server.CreateObject("ADODB.Connection")    
   
 objConn.Open "Provider=SQLOLEDB; Data Source=localhost; Initial    
Catalog=myAdStuff; UId=sa; Pwd="    
 objConn.Execute "delete from banners where bannerId=" &    
Request.QueryString("bannerId")    
   
 Response.Redirect("banners.asp")    
%>

I told you it was simple to delete a banner! Lets look at this code in more detail:

<%@ Language="VBScript" %>

You should beable to remember what this tag does. It’s an ASP directive that tells the ASP engine that we're using VBScript in our ASP page. Next, we declare our database connection and open it:

 dim objConn    
 set objConn = Server.CreateObject("ADODB.Connection")    
   
 objConn.Open "Provider=SQLOLEDB; Data Source=localhost; Initial    
Catalog=myAdStuff; UId=sa; Pwd="    
   
objConn.Execute "delete from banners where bannerId=" &    
Request.QueryString("bannerId")    
   
objConn.Close    
set objConn = nothing    
   
 Response.Redirect("banners.asp")    
%>

Lastly, we'll use our connection object (yes, you can execute an SQL query using a connection object as well!) to parse the SQL query to delete a banner. If you jump back to the banners.asp page, you’ll notice that when you run your mouse over a banner's [Delete] link, you’ll see something like http://localhost/delbanner.asp?bannerId=23 in the status bar of your browser. It’s the bannerId=23 part of the URL that is used in our SQL query as the id of the banner we'll delete. In our example above, Request.QueryString("bannerId") would evaluate to 23.

Finally, when the command has executed, we close and free our database connection and re-direct the browser back to the list of banners.

That’s all for step one. In step two, we'll display the banners on our Website and track impressions through our management system.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links