Deleting Items from the Shopping Basket


Introduction.  Now we need to develop an ASP that will be used for deleting items from a shopping basket.  The file will be called DeleteItem.asp.  This will be presented after developing stored procedures.

We will create one stored procedure to actually delete the item from the basket called sp_RemoveBasketItem.  The following table displays the name of the stored procedure and the ASP file in which it is called.


Stored Procedure ASP Container




The Stored Procedure.  Now I will list out the stored procedures that you should create using SQL in almost the same way we created the tables.  This file should be called sp_RemoveBasketItem.asp.
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include File=""-->

' Open a connection to our SQL Server database
' We will use the ADO Driver connection

Dim connfoxFire, strSQLCreate
Set connfoxFire = Server.CreateObject("ADODB.Connection")
connfoxFire.ConnectionString="Driver={SQL Server};;" & _
"Database=YourUserName;UID=cis; PWD=csatqu"


' Creating the SQL String to create the stored procedure
strSQLCreate = "CREATE PROCEDURE sp_RemoveBasketItem @idBasket int, @idBasketItem int AS " & _
"delete from basketitem where idBasket = @idBasket and idBasketItem = @idBasketItem"


Set connfoxFire = Nothing

Response.Write "<font size = 5>The SQL has executed</font>"



Like all of the other ASPs based on CREATE SQL commands, these files need to be uploaded to your web and then executed once.  After they have been executed, you should get an error if you try to execute them again because the stored procedures should already be there.  After these sp_name.asp files have been used they should be removed from your space on the server.



The DeleteItem.asp.  The following DeleteItem.asp is called when the Remove hyperlink next to the item in the shopping basket is pressed.  This processing script will
  1. create a connection to the user's shopping basket
  2. Use the stored procedure sp_RemoveBasketItem based on the idBasket and idBasketItem to actually delete the item.
  3. Return you to the Basket.asp for display and further operations.
<%@ Language=VBScript %>

' ****************************************************
' DeleteItem.asp - Deletes the specified item from the
' shopping basket.
' ****************************************************

' Create an ADO database connection
set dbBasketItem = server.createobject("adodb.connection")

' Create a record set
set rsBasketItem = server.CreateObject("adodb.recordset")

' Open the connection using our SQL Server DSN-less connection string
dbBasketItem.ConnectionString="Driver={SQL Server};;" & _
"Database=WildWillies;UID=cis; PWD=csatqu"


' Call the delete item SQL statement and pass in the ID of the 
' basket and the id of the item.

sql = "execute sp_RemoveBasketItem " & session("idBasket") & _
", " & request("idBasketItem")

' Execute the SQL statement
set rsBasketItem = dbBasketItem.Execute(sql)

' Send the user back to the baket page
Response.Redirect "Basket.asp"



Notice that this ASP is essentially purely a processing script.  There isn't any HTML associated with the display.  After the results are developed, the Basket.asp is called to display them.