Sunday, 18 August 2013

put increment number in SESSION variables

put increment number in SESSION variables

I am trying so make a small shopping cart but the issue is with products
when I want to add another product to the cart with other attributes then
it overwrites the existing one, I want to add the same product to the cart
again when there are different attributes.
Below is an example of a product that I added with its id = 1 from the
database.
These are the session variables:
["cart_1"]=>
string(1) "1"
["cart_att1_1"]=>
string(2) "2m"
["cart_att2_1"]=>
string(3) "Rot"
["cart_att3_1"]=>
string(1) "M"
and this is the php code I am using:
function shop() {
$action = $_GET['action'];
if($action == "add") {
$prod_id = $_GET['prod_id'];
$_SESSION['cart_'.$prod_id] = "1";
$lim_nr = $_POST['att_number_lim'];
for ($i = 1; $i < $lim_nr+1; $i++) {
$_SESSION['cart_att'.$i.'_'.$prod_id] =$_POST['att'.$i];
}
}
If you have questions please feel free to ask

No comments:

Post a Comment