Displaying the Shopping Basket
Introduction. Now
we need to develop an ASP that will be used for displaying
the items in a shopping basket. The file will be called Basket.asp.
This will be presented after developing
stored procedures.
We will need two stored procedures to display the shopping basket. One of them we have already developed, sp_CreateBasket. The other, sp_RetrieveBasketItem, is new and this page contains the code for creating it. The following table displays the name of the stored procedures and the ASP file in which it is called. |
Stored Procedure | ASP Container |
sp_CreateBasket
sp_RetrieveBasketItem |
Basket.asp |
The Stored Procedures.
Now I will list out the stored procedure that you should create
using SQL in almost the same way we created the tables. The sp_CreateBasket
was developed in the previous web page so ou do not need to create it
again. This is one of the advantages of using stored procedures,
since once it is created you can use it in other places. Another
advantage is that stored procedures are retained within SQL Server as a
sort of compiled code so that they execute more quickly and don't need
to be recompiled each time they are used.
This file should be called sp_RetrieveBasketItem.asp. The name is a bit misleading since it actually retrieves all of the items in a shopping basket identified by its idBasket. |
<%@ 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_RetrieveBasketItem @idBasket int AS " & _ "select * from basketitem where idBasket = @idBasket" 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 Basket.asp. The following
Basket.asp
will
|
<%@ Language=VBScript %> <HTML> <!-- Basket.asp - Displays the items in the shoppers basket. --> <!-- #include file="include/header.asp" --> <!-- This form will allow the user to update the quantity of the items in the basket --> <form method="post" action="UpdateBasket.asp"> <% ' Check to see if the ID of the basket is blank if session("idBasket") = "" then
end if
else
<% end if %> |
Notice that this ASP page has links to other pages that we have yet to create, such as Shipping.asp or EmptyBasket.asp. |