Domanda

I'm trying to add a variable quantity in a $_SESSION variable and i don't know how to do it here is my code:

$cantidad=$_POST['cantidad'];
$ver=$_SESSION['carro'][$id_producto];

    $ncantidad=$ver+$cantidad;

    echo $ncantidad;
    $_SESSION['carro'][$id_producto][$ncantidad]; 

In here cantidad is how many products of the same kind i want, then I try to add the actual number of product to the new one and then store it in the same variable

Thanks

È stato utile?

Soluzione

I think you just need to assign your quantity to the session variable you prefer, i used quantity as last key, you might want to change it

$_SESSION['carro'][$id_producto]['quantity'] = $ncantidad; 

Altri suggerimenti

I think you should wrote it like this:

$_SESSION['carro'][$id_producto]+=$ncantidad;

// echo $_SESSION['carro'][$id_producto];

see php session for further reading

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top