Jump to content

Help! Shopping cart nightmare...


padams

Recommended Posts

I am trying to get my shopping cart system working for a website that sells linen. The product pages have two dropdown boxes, - the client can select a product and a style that the product comes in. At the moment, the product page is pointing to an addcart page, which works fine - it is bringing the productID, productname, styleID and the price through from my database. But when you click "checkout" and continue through to 'viewcart.php' the price and product name work fine, but the style is not continued through.

 

Here is one of the product pages: www.humphreyb.stacnz.com/pages/bedlinen.php

 

Here are the queries from the addcart.php page:

 

if (isset ($_GET['productID'])) {  // Check for a print ID.

$styleID = (int) $_GET['styleID'];

$stylequery = "SELECT style FROM styles WHERE styleID=$styleID";

$stylename=mysql_query($stylequery);

$style=mysql_fetch_assoc($stylename);

$productID = (int) $_GET['productID'];

$productquery = "SELECT name FROM products WHERE productID = $productID";

$productname = mysql_query ($productquery);

if ($productname) {

while ($row = mysql_fetch_array ($productname, MYSQL_ASSOC)) {

$name = $row['name']." (".$style['style'].")"; }}

 

And here is the relevant code from the viewcart.php page:

 

//Get info for the contents session variable

$_SESSION['names']{$row['productID']} = $row['name'];

$_SESSION['styles']{$row['styleID']} = $row['stylename'];

 

// Calculate the total and sub-totals.

$subtotal = $_SESSION['cart'][$row['productID']]['quantity'] * $_SESSION['cart'][$row['productID']]['price'];

$total += $subtotal;

 

// Print the row.

echo "<tr>

<td align=\"left\" class=\"text\">{$row['name']} ({$row['stylename']})</td>

<td align=\"right\" class=\"text\">\$" . number_format ($_SESSION['cart'][$row['productID']]['price'], 2) . "</td>

<td align=\"center\" class=\"text\"><input type=\"text\" size=\"3\" name=\"qty[{$row['productID']}]\" value=\"{$_SESSION['cart'][$row['productID']]['quantity']}\" /></td>

<td align=\"right\" class=\"text\">$" . number_format ($subtotal, 2) . "</td>

</tr>\n";

} // End of the WHILE loop.

 

The assignment is due tomorrow and everything has to be 100% working!

 

Appreciate all the help.

Link to comment
https://forums.phpfreaks.com/topic/131558-help-shopping-cart-nightmare/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.