hi everyone. i'm trying to make a (very) simple shopping cart for my class. i'm stuck on the qty update - it says it's not defined. i think it may have something to do with when i check to see if the form has been submitted yet or not. any help would totally rock!
here's the first page (which works fine)

<?xml version = "1.0"?>
"-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns = "http://www.w3.org/1999/xhtm">

<title> Todd Infinger Final Exam </title>
<font size = "+2" color = "Blue"><center>Welcome to Todd's Store!</font><br/><br/>
<font color = "blue">Here is our product list:</font><br/>
<cfquery name = "toddsproducts" datasource = "tri1_scartwpics2">

select [Products.ProductID], [Products.ProductName], [Products.ProductQty], [Products.ProductPrice], [Suppliers.SupplierName], [Products.ProductPhoto]
from Suppliers inner join Products on [Suppliers].[SupplierID] = [Products].[SupplierID]
<table border = "1" cellspacing = "0">
<td width = "10%" bordercolor = "red"><b><center>Product ID</center></b></td>
<td width = "15%" bordercolor = "red"><b><center>Product Name</center></b></td>
<td width = "10%" bordercolor = "red"><b><center>Product Quantity</center></b></td>
<td width = "10%" bordercolor = "red"><b><center>Product Price</center></b></td>
<td width = "15%" bordercolor = "red"><b><center>Brand</center></b></td>
<td width = "15%" bordercolor = "red"><b><center>Product Photo</center></b></td>
<td width = "10%" bordercolor = "red"><b><center>Buy</center></b></td>
<cfoutput query = "toddsproducts">
<td width = "10%" bordercolor = "red"><center>#toddsproducts.ProductID#</center></td>
<td width = "15%" bordercolor = "red"><center>#toddsproducts.ProductName#</center></td>
<td width = "10%" bordercolor = "red"><center>#toddsproducts.ProductQty#</center></td>
<td width = "10%" bordercolor = "red"><center>#NumberFormat(toddsproducts.ProductPrice, "$_,___.__")#</center></td>
<td width = "15%" bordercolor = "red"><center>#toddsproducts.SupplierName#</td>
<td width = "15%" bordercolor = "red"><center><img width = "120" height = "120" src = #toddsproducts.ProductPhoto#></img></center></td>
<td width = "10%" bordercolor = "red"> &nbsp; 
<cfif toddsproducts.productqty gt 0>
<a href="shoppingcart.cfm?productid=#toddsproducts.productid#&productname=#toddsproducts.productname#&brand=#toddsproducts.suppliername#&price=#toddsproducts.productprice#&qty=1&qtyAvail=#toddsproducts.ProductQty#"><center>Add to Cart</center></a>
		<center>Out of stock!</center>

and here's the second i'm struggling with

<font size="+2" color="magenta"><center>Your shopping cart<center></font><br><br>

<cfset session.productid= url.ProductID>
<cfset session.productname= url.ProductName>
<cfset session.productprice= url.Price>

<cfif NOT isDefined("form.submit")>AND NOT IsDefined("Form.Update")>
<cfset session.qty = 1>
<cfset ItemTotal = (session.productprice * session.qty)>
<cfset OrderTotal = ItemTotal>
<cfset Tax = OrderTotal * 0.07>
<cfset TotalOrderAmount = OrderTotal + Tax>
<cfset session.qty = url.qty>
<cfset ItemTotal = (session.productprice * session.qty)>
<cfset OrderTotal = ItemTotal>
<cfset Tax = OrderTotal * 0.07>
<cfset TotalOrderAmount = OrderTotal + Tax>

        <table border = "1" cellspacing = "0" bordercolor="red">
                        <td bgcolor="pink"><b><font color="magenta">Product Code</font></b></td>
                        <td bgcolor="pink"><b><font color="magenta">Product Name</font></b></td>
                        <td bgcolor="pink"><b><font color="magenta">Unit Price</font></b></td>
                        <td bgcolor="pink"><b><font color="magenta">Quantity Ordered</font></b></td>
                        <td bgcolor="pink"><b><font color="magenta">Total Cost</font></b></td>
                        <td height="43"><cfoutput>#session.productid#</cfoutput></td>
				<cfform action="shoppingcart.cfm?productid=#session.productid#&productname=#session.productname#&price=#session.productprice#&qty=#form.newqty#" method="submit">
                                <input type="text" size = "5" name="newqty">
                                <input type="submit" value="Update" >
                        <td align="right"><cfoutput>#DollarFormat(ItemTotal)#</cfoutput></td>
                <tr><td colspan=4 align="left">Total</td>
                        <td align=right><cfoutput>#DollarFormat(OrderTotal)#</cfoutput></td>

                        <td colspan=4 align="left">Tax (7%)</td>
                        <td align=right><cfoutput>#DollarFormat(Tax)#</cfoutput></td>
                        <td colspan=4 align="left">Total Order Amount</td>

                        <td align=right><cfoutput>#DollarFormat(TotalOrderAmount)#</cfoutput></td>


8 Years
Discussion Span
Last Post by terrymodular

You seem to be carrying too many urls

Try this:
To update the qty - you only need the productid , qty and sessionid

1) Initial Query - why the brackets?

Make this a little cleaner:
The join is there and easier to read

<CFquery name="getproducts" datasource="#application.ds#>


FROM products, suppliers

WHERE products.supplierid=suppliers.supplierid

ORDER by sku 

2)Products List - Make sure in your output query = group="productid" , that will insure only one listing for each product.

1.2) In the product update - I would get rid of

Here's why - you only need to carry the productid, updated qty,

there is no reason to pass the productname, supplier ,etc
Any query on the next pages can supply that info just like you did,
when you queried this

this will clean up your code alot

3) When you finally want your customer to check out - you should have created 2 "Orders" related tables -

3.1) OrderInfo = orderid, customerid , shipping info, etc

3.2) Orderitems table -You would insert the orderid, productid,
qty, saleprice ( Use number format = not dollar ) color, etc. into this table

Now you can go to your invoice ( show cart ) and update , delete or add more items.

Hope this helps.


This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.