Help on Simple Shopping Cart..[SOLVED]
Posted: Wed Nov 02, 2005 7:36 pm
Well im working on the very beginning of my shopping cart, for a website im making for a compitition for school. And i just started making the shopping cart, its and the very early stages, and right now im making it so it saves everything in your cookies. In a line, and using regex to split them.. well here just check out my code so far..
The problem im having is, when i do index.php?add=1 , it will show
Untill i do it again, then it will show the 1 at the end, like it should, but if i do that, and close the page, open it again, it will show the 1, or if there are 3 items, and i close it and reload it again it will show 4, try it your self, you will see what i mean.
I just want it to show up the first time.. : p
Thanks..
-NSF
Code: Select all
<?php
//include('../includes/data.php');
if(isset($_COOKIE['cart']) & $_COOKIE['cart']!='' & $_GET['add']==''){
prin();
}
if(isset($_GET['add'])){
$add=$_GET['add'];
encode($add);
prin();
}
function prin(){
$cart = preg_split('/&/', $_COOKIE['cart']);
print '<pre>';
print_r ($cart);
print '</pre>';
}
function encode($new){
if(isset($_COOKIE['cart']) & $_COOKIE['cart']!=''){
$cart=$_COOKIE['cart'];
$cart=$cart . '&' . $new;
setcookie("cart", $cart);
}else{
setcookie("cart", $new);
}
}
print '<br><br><br><a href="remove.php">Remove cookie</a>';
?>The problem im having is, when i do index.php?add=1 , it will show
Code: Select all
Array
(
[0] =>
)I just want it to show up the first time.. : p
Thanks..
-NSF