<?php
require_once('include.php');
//1.接受传递过来的post参数
$u_id = $_SESSION["id"];
$g_id = intval($_POST["g_id"]);
//2.准备要添加的购物车数据
$sql = "select * from good where g_id='{$g_id}'";
$data = $admindb->ExecSQL($sql,$conn);
$g_name = $data[0]['g_name'];
$s_num = intval($_POST["s_num"]);
//$creatime = time();
$g_discount_price = $data[0]['g_discount_price'];
$g_angle_img = $data[0]['g_angle_img'];
//完成购物车数据的添加操作
$sql = "insert into shopcar(user_id,good_id,s_name,s_sum,s_createtime,s_price,s_img)
values('{$u_id}','{$g_id}','{$g_name}','{$s_num}',now(),'{$g_discount_price}','{$g_angle_img}')";
$ShopCarInsert = $admindb->ExecSQL($sql,$conn);
//4.返回最终添加的结果
if($ShopCarInsert){
$response = array(
'errno' =>0,
'errmsg' =>'success',//已添加购物车
'data' => true,
);
}
else{
$response = array(
'errno' =>-1,
'errmsg' =>'未添加入购物车',
'data' => false,
);
}
echo json_encode($response);
?>