i'm doing the shopping cart thing which is shown in the wrox book "beginning php,..."
i realise the book isn't that great and has a couple of flaws i want to deal with now.
their messageboard isn't much help..
-when i refresh the add page, the item i just added gets added again.
-in my shopping cart each time i added an item, it is being displayed in it's own row, so i have multiple rows with the same item and a quantity. can't i just show each item once and add the quantities ? (GROUP BY prodnum doesn't work)
i have sessions stored in a temp table.
my cart code.
(i'm getting rid of tables of course when i get this to work properly)
<?php
session_id();
session_start();
$sessid = session_id();
$query = "SELECT * FROM br_carttemp WHERE sess = '$sessid'";
$result = mysql_query($query)
or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows;?>
<table border="1">
<tr>
<td>quantity</td>
<td>item name</td>
<td>price each</td>
<td>extended price</td>
<td></td>
<td></td>
</tr>
<tr>
<?php
while ($row = mysql_fetch_array($result)){
extract ($row);
$prod = "SELECT * FROM br_products WHERE prodnum = '$prodnum'";
$prod2 = mysql_query($prod);
$prod3 = mysql_fetch_array($prod2);
extract ($prod3);
?>
<form method="post" action="index.php?p=15">
<input type="hidden" name="prodnum" value="<?php echo $prodnum; ?>">
<input type="hidden" name="sessid" value="<?php echo $sessid; ?>">
<input type="hidden" name="hidden" value="<?php echo $hidden; ?>">
<td>
<input type="text" name="qty" value="<?php echo $quan; ?>" size="2">
</td>
<td>
<a href="index.php?p=12&prodid=<?php echo $prodnum; ?>"><?php echo $name; ?></a>
</td>
<td><?php echo $price; ?></td>
<td>
<?php //get extended price
$extprice = number_format($price * $quan, 2);
echo $extprice; ?>
</td>
<td>
<input type="submit" name="submit" value="change qty"></form>
</td>
<td><form method="post" action="index.php?p=16">
<input type="hidden" name="prodnum" value="<?php echo $prodnum; ?>">
<input type="hidden" name="qty" value="<?php echo $quan; ?>">
<input type="hidden" name="hidden" value="<?php echo $hidden; ?>">
<input type="hidden" name="sessid" value="<?php echo $sessid; ?>">
<input type="submit" name="submit" value="delete item">
</form></td>
</tr>
<?php
//add extended price to total price
$total = $extprice + $total;
} ?>
<tr>
<td colspan="3">total before shipping is</td>
<td><?php echo number_format($total, 2); ?></td>
<td></td>
<td></td>
<form method="post" action="index.php?p=17">
<input type="submit" name="submit" value="proceed to checkout"></form>
</tr>
</table>