Adding Items to the Shopping Basket
Introduction. Now
we need to develop an ASPs that will likely be used for adding items to
a shopping basket. The file will be called AddItem.asp.
This will be presented after developing
stored procedures.
We will create four stored procedures to create the shopping basket, insert a basket item, check the quantity for an item, and update the item quantity. The following table displays the name of the stored procedure and the ASP file in which it is called. |
Stored Procedure | ASP Container |
sp_CreateBasket
sp_InsertBasketItem sp_CheckBasketItemQuantity sp_UpdateBasketItemsQuantity |
AddItem.asp |
The Stored Procedures. 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_CreateBasket.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' 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}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_CreateBasket @idShopper int AS " & _ " insert into basket(idShopper) values(@idShopper) " & _ "select idbasket = @@identity" connfoxFire.execute(strSQLCreate) connfoxFire.Close Set connfoxFire = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
This next file should be called sp_InsertBasketItem.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' 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}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_InsertBasketItem " & _ "@idBasket int, @intQuantity int,@intPrice int,@chrName varchar(255), " & _ "@idProduct int,@chrSize varchar(50),@chrColor varchar(50) AS " & _ "insert into basketitem(idBasket, intQuantity, intPrice, chrName, idProduct, chrSize, chrColor) " & _ " values(@idBasket, @intQuantity, @intPrice, @chrName, @idProduct, @chrSize, @chrColor)" connfoxFire.execute(strSQLCreate) connfoxFire.Close Set connfoxFire = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
This next file should be called sp_CheckBasketItemQuantity.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' 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}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_CheckBasketItemQuantity @idProduct int, @idBasket int AS " & _ "select intQuantity from basketitem where idProduct = @idProduct and idBasket = @idBasket" connfoxFire.execute(strSQLCreate) connfoxFire.Close Set connfoxFire = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
This next file should be called sp_UpdateBasketItemsQuantity.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' 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}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_UpdateBasketItemsQuantity " & _ "@idBasket int, @intQuantity int,@idProduct int AS " & _ "update basketitem set intQuantity = @intQuantity " & _ "where idBasket = @idbasket and idProduct = @idProduct" connfoxFire.execute(strSQLCreate) connfoxFire.Close 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 AddItem.asp. The following
AddItem.asp
will
|
<%@ Language=VBScript %> <% ' **************************************************** ' AddItem.asp - This page is utlized to add a selected ' product into the shopping basket. ' **************************************************** ' Check to see if a shopper variable has been set. If not then default to 0. if session("idShopper") = "" then
end if
End If
else
end if |