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!
todrik
here's the first page (which works fine)

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtm">

<head>
<title> Todd Infinger Final Exam </title>
</head>
<body>
<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]
</cfquery>
<table border = "1" cellspacing = "0">
<tr>
<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>
</tr>
<cfoutput query = "toddsproducts">
<tr>
<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>
<cfelse>
		<center>Out of stock!</center>
</cfif>
</center>
</tr>
</cfoutput>
</table></center>
</body>
</html>

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>
<cfelse>
<cfset session.qty = url.qty>
<cfset ItemTotal = (session.productprice * session.qty)>
<cfset OrderTotal = ItemTotal>
<cfset Tax = OrderTotal * 0.07>
<cfset TotalOrderAmount = OrderTotal + Tax>
</cfif>


<center>
       
        <table border = "1" cellspacing = "0" bordercolor="red">
                <tr>
                        <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>
                </tr>
                <tr>
                        <td height="43"><cfoutput>#session.productid#</cfoutput></td>
                        <td><cfoutput>#session.productname#</cfoutput></td>
                        <td><cfoutput>#DollarFormat(session.productprice)#</cfoutput></td>
                        <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" >
				</cfform>
                               
                        </td>
                        <td align="right"><cfoutput>#DollarFormat(ItemTotal)#</cfoutput></td>
                </tr>
                <tr><td colspan=4 align="left">Total</td>
                        <td align=right><cfoutput>#DollarFormat(OrderTotal)#</cfoutput></td>

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

                        <td align=right><cfoutput>#DollarFormat(TotalOrderAmount)#</cfoutput></td>
                </tr>
                
        </table></center>
        <br>

       

</body>
</html>

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#>

SELECT
products.productid,
products.productname,
prducts.supplierid,
products.saleprice,
products.color,
products.sku,
suppliers.supplierid,
suppliers.company

FROM products, suppliers

WHERE products.supplierid=suppliers.supplierid

ORDER by sku 
</cfquery>

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
productname=#toddsproducts.productname#&brand=#toddsproducts.suppliername#&price=#toddsproducts.productprice#

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.

Terry

This article has been dead for over six months. Start a new discussion instead.