<?php
header("Content-type: text/html; charset=utf-8");
session_start();//啟動session
# // session_destroy();
// die();
// var_dump($_SESSION);
// die();
if(isset($_SESSION['username']) &&!empty($_SESSION[ 'username'])){
}
else{
echo '<script language="JavaScript">;
);</script>';
echo "<script>location.href='header.php'</script>"; exit;
/ $; = $_SESSION['uid'];
$goods_id = $_POST['goods_id'];//取得商品id
// $size = $_POST['size'];
// $ color = $_POST['color'];
$number = $_POST['num'];//取得商品數量 // $numcol="$size"."$color"; // var_dump($_POST );
// die();
if(empty($_SESSION["gwc"])) { //1.購物車是空的,第一次點選點擊車 $arr[$goods_id] =array(
'goods_id' => $goods_id # umber
); "gwc"]=$arr; // print_r($arr);
// die();
} else { = $_SESSION["gwc"]; //先存一下 $chuxian = false; //查詢是否有該商品,KEY是商品id
foreach($arr as $kEY是商品id
foreach($arr as $k=>
{
if($k==$goods_id)
{ $chuxian = true; } }
$arr[$goods_id]['num '] =$number; //3.如果購物車上有商品
//if(!isset($arr[$goods_
// 'id' => $goods_id,
}
// {
// $arr[$goods_id]['num'] =$number;
// }
arr;
}
else
{ //2.為購物車中沒有該商品
; $goods_id,
# 'num' => $number
# );
// print_r($arr);
// die();
} } OK";
echo '<script language="JavaScript">;
alert("新增成功!");location.href="header.php";;';
;
#
?>