如何保留或存储以前的会话帖子值到另一个页面?

时间:2013-04-12 13:13:00

标签: php session shopping-cart shopping

我有两个页面产品和购物车,但问题是,当我将$_SESSION['itemcode']发布到购物车页面然后select query working但是当页面重定向到产品continue shopping时,新产品覆盖旧产品?

产品页面

session_start();
if(isset($_POST['size']))
{

$_SESSION['pid']= implode (",",$_POST['pid']);
$_SESSION['wid2']=$_POST['wid'];
$_SESSION['itemcode3']=$_POST['itemcode'];
if($_REQUEST['command']=='add' && $_REQUEST['id']){
$id=$_REQUEST['id'];
addtocart($id,1);
header('location:shoppingcart.php');
exit();
}

<input type="button" class="button1" name="check" value="Add To Cart" 
 onclick="addtocart(<?php echo $row3['id'];?>);" />

$length= count($_POST['product']);
for($i=0; $i<$length; $i++)
{
$size=$_POST['size'];

$query2=mysql_query("INSERT INTO mywishlist VALUES 
('','$id','".$_SESSION['id']."','".$_SESSION['email']."','".$_POST['itemcode']  
[$i]."','".$_POST['product'][$i]."','$size','".$_POST['price']
[$i]."','".$_POST['image1'][$i]."','')")
or die ("My Wish List");
}

购物车页面

session_start();
$itemcode2=implode(',',$_SESSION['itemcode3']);

$querycart=mysql_query("SELECT * FROM products INNER JOIN mywishlist ON 
products.`id`=mywishlist.`pid` 
WHERE  mywishlist.itemcode='".$itemcode2."' ")
or die ("shoppingcart query"); 
while($rowcart=mysql_fetch_assoc($querycart))
{   
?>
<?php echo $rowcart['itemcode']; ?>
<?php echo $rowcart['products']; ?>
<?php echo $rowcart['qty']; ?>
<?php echo $rowcart['price']; ?>

<?php }?>

1 个答案:

答案 0 :(得分:0)

您还需要在开头的产品页面中致电session_start();。还要确保在将输入传递给查询之前清理输入