I have this loop where i'm adding items to a session array. like this:
$SQL = "SELECT * FROM tbl_product where id ='{$cartid}'";
//execute the query
$result = mysql_query($SQL);
//add the resultant data into a session array
while($row = mysql_fetch_assoc($result)){
$_SESSION['cartItems'][] = $row;
}
Somewhere in my HTML document, i'm displaying the retrieved items in a table:
foreach($_SESSION['cartItems'] as $product){
echo '</tr>';
echo ' <td class="product">'.$product['name'].'</td>';
echo'<td class="quantity"><input type="text" value='.$product['quantity'].' class="inputform"/></td>';
echo '<td class="item_price">'.$product['price'].'</td>';
echo '<td class="item_total">'.$product['user'].'</td>';
echo '<td class="item_remove"><a href = "cart-page.php?delid='.$product['id'].'" style="color:red">Remove Product</a></td>';//to delete an item
echo '</tr>';
}
The problem is when i reload the page, the last entry in the table row gets duplicated i.e an identical row is automatically added. If i reload a hundred times, hundred identical rows will be added. That is very strange to me. Any ideas why i'm having this error? thanks