搜尋

首頁  >  問答  >  主體

在用戶添加商品到購物車保存到session後,怎麼把購物車的資訊儲存到資料庫

<?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";;';
         
        ;
  
#  
 ?>

cyjy622cyjy6221823 天前982

全部回覆(0)我來回復

無回覆
  • 取消回覆