I have a shooping cart and I would like to save the $_SESSION[‘cart’] which contains the $product_id => $quantity of the products that the user have choosen.
For example:
[cart] => Array
(
[366] => 2000
[215] => 456
)
First I serialize the $_SESSION[‘cart’] before I INSERT IT in my data base.
<?php
if($_SESSION['cart'])
{
$pedido= serialize($_SESSION['cart']);
}
?>
$sql1="insert into pedido(orden) values ('$pedido')";
Now in a different page I want to view the $_SESSION[‘cart’]. So I use:
$sql2 = "SELECT orden FROM pedido where id_pedido = '$ID'";
$rs2 = mysql_query($sql2, $conexio) or die("Error al consultar: ".mysql_error());
$row2 = mysql_fetch_row($rs2);
$id_usuario=$row2[0];
$_SESSION['cartguardado']= unserialize($id_usuario);
I know that In this last step I am doing something wrong. Any body could help me and help me finding the mistake?
Try to output $row2
if $row2[0] is empty so something wrong with your data