Make Revenue With Your Own Banner Management System - Deleting a banner
(Page 7 of 11 )
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 have created the page, you can click on the [ Delete ] link from the "Current Banners in Rotation" page to remove a banner from the list. Create a new page called delbanner.asp and add the following 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 the code above in more detail:
objConn.Execute "delete from banners where bannerId=" & Request.QueryString("bannerId")
objConn.Close
set objConn = nothing
Response.Redirect("banners.asp")
%>Once we have made a connection to the database, we will 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 the [Delete] link of a banner, 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 as the id of the banner to delete in our SQL query. 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 part one of my article on creating a banner management system. In part two, we will display the banners on our website and track impressions through our management system.
Next: Displaying and tracking banners, impressions and click-thrus >>
More ASP Articles
More By Mitchell Harper