jay_bo Posted March 21, 2010 Share Posted March 21, 2010 Could anyone help me on removing and update items in my shopping cart..... This is how items are added... echo '<div id="cart_container">'; echo '<div id="cart">'; $cost = number_format($_SESSION["cost"],2,".",","); echo '<form name="cart" method="post" action="shopping-cart.php" >'; echo '<p class="center"><strong>SHOPPING CART</strong></p>'; echo '<p>No of Items: <strong>'.$_SESSION['products'].'</strong><br/>Total Price: <strong>£'.$_SESSION['cost'].'</strong></p>'; echo '<input type="hidden" name="price" value="'.$row["price"].'">'; echo '<p class="button"><input type="submit" name="Submit" value="Check Out"></p>'; echo '</form>'; echo '<form name="cart" method="post" action="logout.php" >'; echo '<p class="button"><input type="submit" name="Submit" value="Logout"></p>'; echo '</form>'; echo '</div>'; echo '</div>'; This is my shopping cart....... <?php $items = explode(",",$_SESSION["order"]); $sql="SELECT * FROM products"; $result=mysql_query($sql); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { for( $i = 0; $i < count($items); ++$i ) { echo '<form id="form1" name="form1" method="post" action="checkout.php">'; echo '<div id="products">'; if ($items[$i]==$row['product_id']) { echo $row['title']. ' - £'.$row['price'] ; } echo '</div>'; } } echo '<br />'; echo '<input type="submit" name="Submit" value="Pay for Items" />'; echo '</form>'; echo '<form id="form1" name="form1" method="post" action="logout.php">'; echo '<input type="submit" name="Submit" value="Empty Cart" />'; echo '</form>'; ?> Many thanks Link to comment https://forums.phpfreaks.com/topic/196003-shopping-cart/ Share on other sites More sharing options...
peter_anderson Posted March 21, 2010 Share Posted March 21, 2010 Your cart seems to be loading all items from your DB. When an item is added, you should add in the DB the session ID (session_id()), the product ID and the users IP (if you want) Link to comment https://forums.phpfreaks.com/topic/196003-shopping-cart/#findComment-1029554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.