I want to see if someone can help me with a shopping cart I am trying to build?
So far this is what I have in order to pull the items from the db:
<?
require('connect_var.php');
require('connect.php');
echo("
<html>
<head>
<title>Product List</title>
</head>
<body>
");
$sql = "SELECT productID,
productName,
productDesc,
productPrice,
image
FROM products";
$res = mysql_query($sql);
while($prod = mysql_fetch_array($res)) {
$prodID=$prod['productID'];
$prodImage=$prod['image'];
$prodName=$prod['productName'];
$prodDesc=$prod['productDesc'];
$prodPrice=$prod['productPrice'];
echo ("
<table width='750' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='72' rowspan='2' valign='top'>".$prodImage."</td>
<td width='49'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Item #: <b>".$prodID."</b></font></td>
<td width='106'> </td>
<td width='419'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><b>".$prodName."</b></font></td>
<td width='53'> </td>
<td width='104'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><b>\$".$prodPrice."</b></font></td>
</tr>
<tr>
<td colspan='3'><br>
<font size='1' face='Verdana, Arial, Helvetica, sans-serif'>".$prodDesc."</font></td>
<td> </td>
<td width='104'><br>
<form name= method='post' action='/project/view_shopping_cart.php?new=$prodID'>
<input type='submit' value='Add to Cart'>
<input type='hidden' name='prodID' value=".$prodID.">
<input type='hidden' name='prodPrice' value=".$prodPrice.">
<input type='hidden' name='prodName' value=".$prodName.">
<input type='hidden' name='prodQty' value=1>
</form> </td>
</tr>
</table>
<br>
<hr align='left' width='750' noshade><br>
</body>
");
}
echo("
</body>
</html>
");
mysql_close($dblink);
?>
What I need help with is putting each item that the user would add to the cart into an array. Each item has an 'add to cart' button associated with it that will pass the prodID, prodName, prodPrice and prodQty to the page view_shopping_cart.php in a hidden field. I want it to check to see if that item is already in the cart, if not, add it. If it is already there then add another one of the same. I also want them all stored as session vars so it will remember all of the products in case the user leaves and comes back at a later time.
Along with this, I want it to display the total of all products in the cart along with the ability to change the qty of any product with a text box and then update the total.
I hope someone can help me with this or at least get me on the right track as how to do this.
Thanks for your help in advance.