shawntbanks
Programmer
Looking for some help. When I use this code to add to a shopping cart, the first item goes fine, but when I go to add a second and third, the first one and the second disappear. I am puzzled. Any body got a suggestion
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>View Shopping Cart</title>
<cfquery name="get_SubCategories" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
</cfquery>
<cfparam name="form.select_Ad_Subcategory" default="1">
<cfquery name="Fees" datasource="market">
select *
from Private_Prices
Where category_ID = #form.select_Ad_Subcategory#
</cfquery>
<cfquery name="GST" datasource="market">
select *
from taxes
Where tax = 'gst'
</cfquery>
<cfquery name="PST" datasource="market">
select *
from taxes
Where tax = 'pst'
</cfquery>
<cfset WF = 5>
<cfset MF = 10>
<cfinclude template="../Templates/Header_&_Sidebar_for_Place_Ad_Folder_Subcat_Select.cfm">
<td width="600" rowspan="2" valign="top" bgcolor="#FFFFFF">
<table align="center">
<!--- did the user get here from the ad confirmation page? --->
<CFIF IsDefined("FORM" AND IsStruct(FORM) AND NOT StructIsEmpty(FORM) AND IsDefined("FORM.submitid">
<CFSET bValidSubmit = true>
<!--- lock the session scope and check the submitID against the list of previously submitted ads... again --->
<CFLOCK timeout="30" throwontimeout="No" type="READONLY" scope="SESSION">
<CFIF IsDefined("session.submittedIDs" AND ListFind("#session.submittedIDs#",FORM.submitID) GT 0>
<CFSET bValidSubmit = false>
</CFIF>
</CFLOCK>
<CFIF bValidSubmit>
<!--- <cfquery name="Fees" datasource="market">
select * from Private_Prices Where category_ID = #form.select_Ad_Subcategory#
</cfquery>
<cfset WF = 5>
<cfset MF = 10>
if it's a new submitID, create the temporary structure (NOT in the session scope --->
<CFSET strTempItem = StructNew()>
<cfset strtempitem.submitID = form.submitID>
<cfset strtempitem.categoryid = #form.select_Ad_Subcategory#>
<cfset strtempitem.subcategoryid = #form.selectLocal#>
<cfset strtempitem.subcategory = #form.sub#>
<cfset strtempitem.location = #form.location#>
<cfset strtempitem.itemname = #form.Itemname#>
<cfset strtempitem.Short_Description = #form.Short_Description#>
<cfset strtempitem.long_description = #form.long_description#>
<cfset strtempitem.itemprice = #form.itemprice#>
<cfset strtempitem.featured = #form.featured#>
<cfset strtempitem.begindate = form.begindate>
<cfset strtempitem.Enddate = (#form.begindate# + #form.Enddate#)>
<CFSET strTempItem.picture1 = "">
<CFSET strTempItem.picture2 = "">
<CFSET strTempItem.picture3 = "">
<CFSET strTempItem.picture4 = "">
<CFIF IsDefined("FORM.picture1filename" AND Len(Trim(FORM.picture1filename)) GT 0>
<CFSET strTempItem.picture1 = FORM.picture1filename>
</CFIF>
<CFIF IsDefined("FORM.picture2filename" AND Len(Trim(FORM.picture2filename)) GT 0>
<CFSET strTempItem.picture2 = FORM.picture2filename>
</CFIF>
<CFIF IsDefined("FORM.picture3filename" AND Len(Trim(FORM.picture3filename)) GT 0>
<CFSET strTempItem.picture3 = FORM.picture3filename>
</CFIF>
<CFIF IsDefined("FORM.picture4filename" AND Len(Trim(FORM.picture4filename)) GT 0>
<CFSET strTempItem.picture4 = FORM.picture4filename>
</CFIF>
<!--- then lock the session scope and append the new ad to the shopping cart and update the list of previously submitted IDs with the current submitID --->
<CFLOCK timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<CFIF NOT IsDefined("session.auth" or NOT IsArray(session.auth)>
<CFSET session.auth = arraynew(1)>
</CFIF>
<CFSET ArrayAppend(session.auth,strTempItem)>
<CFIF NOT IsDefined("session.submittedIDs">
<CFSET session.submittedIDs = "">
</CFIF>
<CFSET session.submittedIDs = ListAppend("#session.submittedIDs#",FORM.submitID)>
</CFLOCK>
<CFELSE>
<!--- the submitID already exists in the list of previously submitted IDs, so this submission is not valid --->
<tr>
<td><font color="#FF0000" size="2" face="Georgia, Times New Roman, Times, serif">You've
already added this item to your cart.</font></td>
</tr>
</CFIF>
</CFIF>
<!--- regardless of any of the above, display the current cart --->
<tr>
<td><div align="center"><font size="2" face="Georgia, Times New Roman, Times, serif">Here's
your shopping cart:</font></div></td>
</tr>
<CFSET aryLocalArray = ArrayNew(1)>
<!--- readonly lock on the session scope, and copy out the session array to a local array... since we really don't want to keep the lock open while we're looping --->
<CFLOCK timeout="30" throwontimeout="No" type="READONLY" scope="SESSION">
<CFIF IsDefined("session.auth" AND IsArray(session.auth)>
<CFSET aryLocalArray = session.auth>
</CFIF>
</CFLOCK>
</table>
<!--- output the cart contents using the local (NOT session scope) array --->
<table border="0" cellpadding="5" align="center">
<tr bgcolor="#009933" style="color: #FFFFFF;">
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Item
#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Item
Name</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Category</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Listing
Fee</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Featured</font></td>
</tr>
<CFIF ArrayLen(aryLocalArray) GT 0>
<cfset variables.totalListing_fee = 0>
<cfset variables.totalFeatured_fee = 0>
<CFLOOP from="1" to="#ArrayLen(aryLocalArray)#" index="whichItem">
<cfquery name="Get_Cat" datasource="market">
select Subcategory
from subcategory
Where subcategoryID = #aryLocalArray[whichItem].subcategoryid#
</cfquery>
<cfset enddate = aryLocalArray[whichItem].enddate - aryLocalArray[whichItem].Begindate>
<cfif enddate EQ 7>
<cfquery name="Fees" datasource="market">
select * from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'W'
</cfquery><cfelse>
<cfquery name="Fees" datasource="market">
select * from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'M'
</cfquery>
</cfif>
<cfif enddate EQ 7>
<cfquery name="FFEEs" datasource="market">
select Price * 0.40 as feat_total
from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'W'
</cfquery>
<cfelse>
<cfquery name="FFEEs" datasource="market">
select Price * 0.40 as feat_total
from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'M'
</cfquery></cfif>
<CFOUTPUT>
<tr>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">#whichItem#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif"><a href="Review.cfm?itemnum=#whichItem#">#aryLocalArray[whichItem].itemname#</a></font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">#get_cat.subcategory#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">#dollarformat(fees.price)#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif"><cfif aryLocalArray[whichItem].Featured EQ 1>#dollarformat(ffees.feat_total)#</font></cfif></td>
<TD><a href="edit_item.cfm?itemnum=#whichItem#"><font size="2" face="Georgia, Times New Roman, Times, serif">|Modify|</font></a> <a href="delete_item.cfm?itemnum=#whichItem#"><font size="2" face="Georgia, Times New Roman, Times, serif">|Delete|</font></a></TD>
</tr>
<cfset totalListing_fee = totalListing_fee + fees.price>
<cfif aryLocalArray[whichItem].Featured EQ 1>
<cfset totalFeatured_fee = totalFeatured_fee + FFEEs.feat_total></cfif>
</CFOUTPUT>
</CFLOOP>
<cfset Grand_Subtotal = totalListing_fee + totalFeatured_fee>
<cfset Total_GST = Grand_Subtotal * #gst.amount#>
<cfset Total_PST = (Grand_Subtotal + Total_GST) * #PST.amount#>
<cfset Total_taxes = Total_GST + Total_PST>
<cfset Grand_Total = Total_taxes + Grand_Subtotal>
<tr>
<td colspan="6"><hr></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">SubTotal
Listing Fees</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><cfoutput>#Dollarformat(totalListing_fee)#</cfoutput> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">SubTotal
Featured</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><u><cfoutput>#Dollarformat(totalFeatured_fee)#</cfoutput> </u> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">Grand
SubTotal </font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><cfoutput>#Dollarformat(Grand_Subtotal)#</cfoutput> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">Taxes</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><u><cfoutput>#Dollarformat(Total_Taxes)#</cfoutput> </u> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">Total</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><strong><cfoutput>#Dollarformat(Grand_total)#</cfoutput></strong> </font></td>
<td></td>
</tr>
<CFELSE>
<tr>
<td colspan="3">No items currently in cart</td>
</tr>
</CFIF>
</table>
<table align="center" border="0">
<tr><td colspan="2"><hr></td></tr>
<tr>
<td width="200"><div align="center"><a href="page1.cfm"><img src="../images/new_item.gif" border="0"></a></div></td>
<td width="200"><div align="center"><a href="Checkout.cfm"><img src="../images/checkout.gif" border="0"></a></div></td>
</tr>
</table>
<tr>
<td background="../images/top_space2.gif"><img src="../images/top_space2.gif"></td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>View Shopping Cart</title>
<cfquery name="get_SubCategories" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
</cfquery>
<cfparam name="form.select_Ad_Subcategory" default="1">
<cfquery name="Fees" datasource="market">
select *
from Private_Prices
Where category_ID = #form.select_Ad_Subcategory#
</cfquery>
<cfquery name="GST" datasource="market">
select *
from taxes
Where tax = 'gst'
</cfquery>
<cfquery name="PST" datasource="market">
select *
from taxes
Where tax = 'pst'
</cfquery>
<cfset WF = 5>
<cfset MF = 10>
<cfinclude template="../Templates/Header_&_Sidebar_for_Place_Ad_Folder_Subcat_Select.cfm">
<td width="600" rowspan="2" valign="top" bgcolor="#FFFFFF">
<table align="center">
<!--- did the user get here from the ad confirmation page? --->
<CFIF IsDefined("FORM" AND IsStruct(FORM) AND NOT StructIsEmpty(FORM) AND IsDefined("FORM.submitid">
<CFSET bValidSubmit = true>
<!--- lock the session scope and check the submitID against the list of previously submitted ads... again --->
<CFLOCK timeout="30" throwontimeout="No" type="READONLY" scope="SESSION">
<CFIF IsDefined("session.submittedIDs" AND ListFind("#session.submittedIDs#",FORM.submitID) GT 0>
<CFSET bValidSubmit = false>
</CFIF>
</CFLOCK>
<CFIF bValidSubmit>
<!--- <cfquery name="Fees" datasource="market">
select * from Private_Prices Where category_ID = #form.select_Ad_Subcategory#
</cfquery>
<cfset WF = 5>
<cfset MF = 10>
if it's a new submitID, create the temporary structure (NOT in the session scope --->
<CFSET strTempItem = StructNew()>
<cfset strtempitem.submitID = form.submitID>
<cfset strtempitem.categoryid = #form.select_Ad_Subcategory#>
<cfset strtempitem.subcategoryid = #form.selectLocal#>
<cfset strtempitem.subcategory = #form.sub#>
<cfset strtempitem.location = #form.location#>
<cfset strtempitem.itemname = #form.Itemname#>
<cfset strtempitem.Short_Description = #form.Short_Description#>
<cfset strtempitem.long_description = #form.long_description#>
<cfset strtempitem.itemprice = #form.itemprice#>
<cfset strtempitem.featured = #form.featured#>
<cfset strtempitem.begindate = form.begindate>
<cfset strtempitem.Enddate = (#form.begindate# + #form.Enddate#)>
<CFSET strTempItem.picture1 = "">
<CFSET strTempItem.picture2 = "">
<CFSET strTempItem.picture3 = "">
<CFSET strTempItem.picture4 = "">
<CFIF IsDefined("FORM.picture1filename" AND Len(Trim(FORM.picture1filename)) GT 0>
<CFSET strTempItem.picture1 = FORM.picture1filename>
</CFIF>
<CFIF IsDefined("FORM.picture2filename" AND Len(Trim(FORM.picture2filename)) GT 0>
<CFSET strTempItem.picture2 = FORM.picture2filename>
</CFIF>
<CFIF IsDefined("FORM.picture3filename" AND Len(Trim(FORM.picture3filename)) GT 0>
<CFSET strTempItem.picture3 = FORM.picture3filename>
</CFIF>
<CFIF IsDefined("FORM.picture4filename" AND Len(Trim(FORM.picture4filename)) GT 0>
<CFSET strTempItem.picture4 = FORM.picture4filename>
</CFIF>
<!--- then lock the session scope and append the new ad to the shopping cart and update the list of previously submitted IDs with the current submitID --->
<CFLOCK timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<CFIF NOT IsDefined("session.auth" or NOT IsArray(session.auth)>
<CFSET session.auth = arraynew(1)>
</CFIF>
<CFSET ArrayAppend(session.auth,strTempItem)>
<CFIF NOT IsDefined("session.submittedIDs">
<CFSET session.submittedIDs = "">
</CFIF>
<CFSET session.submittedIDs = ListAppend("#session.submittedIDs#",FORM.submitID)>
</CFLOCK>
<CFELSE>
<!--- the submitID already exists in the list of previously submitted IDs, so this submission is not valid --->
<tr>
<td><font color="#FF0000" size="2" face="Georgia, Times New Roman, Times, serif">You've
already added this item to your cart.</font></td>
</tr>
</CFIF>
</CFIF>
<!--- regardless of any of the above, display the current cart --->
<tr>
<td><div align="center"><font size="2" face="Georgia, Times New Roman, Times, serif">Here's
your shopping cart:</font></div></td>
</tr>
<CFSET aryLocalArray = ArrayNew(1)>
<!--- readonly lock on the session scope, and copy out the session array to a local array... since we really don't want to keep the lock open while we're looping --->
<CFLOCK timeout="30" throwontimeout="No" type="READONLY" scope="SESSION">
<CFIF IsDefined("session.auth" AND IsArray(session.auth)>
<CFSET aryLocalArray = session.auth>
</CFIF>
</CFLOCK>
</table>
<!--- output the cart contents using the local (NOT session scope) array --->
<table border="0" cellpadding="5" align="center">
<tr bgcolor="#009933" style="color: #FFFFFF;">
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Item
#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Item
Name</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Category</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Listing
Fee</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">Featured</font></td>
</tr>
<CFIF ArrayLen(aryLocalArray) GT 0>
<cfset variables.totalListing_fee = 0>
<cfset variables.totalFeatured_fee = 0>
<CFLOOP from="1" to="#ArrayLen(aryLocalArray)#" index="whichItem">
<cfquery name="Get_Cat" datasource="market">
select Subcategory
from subcategory
Where subcategoryID = #aryLocalArray[whichItem].subcategoryid#
</cfquery>
<cfset enddate = aryLocalArray[whichItem].enddate - aryLocalArray[whichItem].Begindate>
<cfif enddate EQ 7>
<cfquery name="Fees" datasource="market">
select * from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'W'
</cfquery><cfelse>
<cfquery name="Fees" datasource="market">
select * from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'M'
</cfquery>
</cfif>
<cfif enddate EQ 7>
<cfquery name="FFEEs" datasource="market">
select Price * 0.40 as feat_total
from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'W'
</cfquery>
<cfelse>
<cfquery name="FFEEs" datasource="market">
select Price * 0.40 as feat_total
from Private_Prices
Where category_ID = #aryLocalArray[whichItem].categoryid# and listing_code = 'M'
</cfquery></cfif>
<CFOUTPUT>
<tr>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">#whichItem#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif"><a href="Review.cfm?itemnum=#whichItem#">#aryLocalArray[whichItem].itemname#</a></font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">#get_cat.subcategory#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif">#dollarformat(fees.price)#</font></td>
<td><font size="2" face="Georgia, Times New Roman, Times, serif"><cfif aryLocalArray[whichItem].Featured EQ 1>#dollarformat(ffees.feat_total)#</font></cfif></td>
<TD><a href="edit_item.cfm?itemnum=#whichItem#"><font size="2" face="Georgia, Times New Roman, Times, serif">|Modify|</font></a> <a href="delete_item.cfm?itemnum=#whichItem#"><font size="2" face="Georgia, Times New Roman, Times, serif">|Delete|</font></a></TD>
</tr>
<cfset totalListing_fee = totalListing_fee + fees.price>
<cfif aryLocalArray[whichItem].Featured EQ 1>
<cfset totalFeatured_fee = totalFeatured_fee + FFEEs.feat_total></cfif>
</CFOUTPUT>
</CFLOOP>
<cfset Grand_Subtotal = totalListing_fee + totalFeatured_fee>
<cfset Total_GST = Grand_Subtotal * #gst.amount#>
<cfset Total_PST = (Grand_Subtotal + Total_GST) * #PST.amount#>
<cfset Total_taxes = Total_GST + Total_PST>
<cfset Grand_Total = Total_taxes + Grand_Subtotal>
<tr>
<td colspan="6"><hr></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">SubTotal
Listing Fees</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><cfoutput>#Dollarformat(totalListing_fee)#</cfoutput> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">SubTotal
Featured</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><u><cfoutput>#Dollarformat(totalFeatured_fee)#</cfoutput> </u> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">Grand
SubTotal </font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><cfoutput>#Dollarformat(Grand_Subtotal)#</cfoutput> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">Taxes</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><u><cfoutput>#Dollarformat(Total_Taxes)#</cfoutput> </u> </font></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><font face="Georgia, Times New Roman, Times, serif">Total</font></td>
<td><font face="Georgia, Times New Roman, Times, serif"><strong><cfoutput>#Dollarformat(Grand_total)#</cfoutput></strong> </font></td>
<td></td>
</tr>
<CFELSE>
<tr>
<td colspan="3">No items currently in cart</td>
</tr>
</CFIF>
</table>
<table align="center" border="0">
<tr><td colspan="2"><hr></td></tr>
<tr>
<td width="200"><div align="center"><a href="page1.cfm"><img src="../images/new_item.gif" border="0"></a></div></td>
<td width="200"><div align="center"><a href="Checkout.cfm"><img src="../images/checkout.gif" border="0"></a></div></td>
</tr>
</table>
<tr>
<td background="../images/top_space2.gif"><img src="../images/top_space2.gif"></td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>