<?php
require_once('include.php');
//1.接受傳遞過(guò)來(lái)的post參數(shù)
$u_id?=?$_SESSION["id"];
$g_id?=?intval($_POST["g_id"]);
//2.準(zhǔn)備要添加的購(gòu)物車(chē)數(shù)據(jù)
$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'];
//完成購(gòu)物車(chē)數(shù)據(jù)的添加操作
$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.返回最終添加的結(jié)果
if($ShopCarInsert){
????$response?=?array(
????????'errno'?=>0,
????????'errmsg'?=>'success',//已添加購(gòu)物車(chē)
????????'data'?=>?true,
????);
}
else{
????$response?=?array(
????????'errno'?=>-1,
????????'errmsg'?=>'未添加入購(gòu)物車(chē)',
????????'data'?=>?false,
????);
}
echo?json_encode($response);
?>



2017-10-27
看你數(shù)據(jù)庫(kù)連接的代碼有輸出錯(cuò)誤異常嗎?PHP中沒(méi)有now(),如果是time()的話,數(shù)據(jù)庫(kù)相應(yīng)的類(lèi)型也要改
2017-10-26
$ShopCarInsert結(jié)果有問(wèn)題吧,或是打印一下最后一條sql語(yǔ)句看一下