Thanks again LordShryku. It now does what I want it to.
Although now I have another question. I have changed the page a little bit so that every item in the array will display with an 'add to cart' button instead of a text box to have the user enter in the qty they wish to purchase. The code is as follows:
$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'>
<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>
");
}
Once the user selects an item it will take them to their shopping cart and display what they have in it. Problem is, how can I make it has an array to keep displaying what they have in their shopping cart until it reaches the end, sort of like the latter when pulling from the db?
This is what I tried doing but it keeps going in an endless loop becuase $prodID will always be true:
<?
session_start();
$_SESSION['prodID'] = $prodID;
$_SESSION['prodQty'] = $prodQty;
$_SESSION['prodPrice'] = $prodPrice;
$_SESSION['prodName'] = $prodName;
if($prodID){
$productTotal=$prodQty * $prodPrice;
echo ("
<table width='592' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td colspan='2'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><strong>You
have the following items in your shopping cart:</strong></font></td>
<td width='92'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'> </font></td>
</tr>
<tr>
<td width='62'> </td>
<td width='438'> </td>
<td> </td>
</tr>
<tr>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Qty:</font></strong></td>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Name:</font></strong></td>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Price:</font></strong></td>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Total:</font></strong></td>
</tr>");
while($prodID){
echo ("
<tr>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><input type='text' value=".$prodQty."></font></strong></td>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>".$prodName."</font></strong></td>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>".$prodPrice."</font></strong></td>
<td><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>".$productTotal."</font></strong></td>
</tr>
");
}
echo ("</table>
<br>
<br>
<a href='/project/products2.php'>Continue Shopping</a>");
}
?>
Any suggestions? Is this also correct for storing their sessions and cookies in case they come back at a later date, so it will still display what is in their cart?
Thanks