久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

PHP接收json并將接收數(shù)據(jù)插入數(shù)據(jù)庫

瀏覽:133日期:2022-09-12 13:02:02

最近有一個需求,前端向后臺提交json,后臺解析并且將提交的值插入數(shù)據(jù)庫中,

難點1、php解析json(這個不算難點了,網(wǎng)上實例一抓一大把)2、解析json后,php怎樣拿到該拿的值

<?phprequire (’connect.php’);/*本例用到的數(shù)據(jù):post_array={'order_id':'0022015112305010013','buyer_id':'2','seller_id':'1','all_price':'100.00','json_list':[{'product_id':'3','product_number':'3'},{'product_id':'8','product_number':'2'},{'product_id':'10','product_number':'4'}]} */$post_array=$_POST[’post_array’];//--解析Json,獲取對應(yīng)的變量值$obj=json_decode($post_array,TRUE);$order_id = $obj[’order_id’];$buyer_id = $obj[’buyer_id’];$seller_id = $obj[’seller_id’];$all_price = $obj[’all_price’];$i=0;//循環(huán)變量//--得到Json_list數(shù)組長度$num=count($obj['json_list']);//--遍歷數(shù)組,將對應(yīng)信息添加入數(shù)據(jù)庫for ($i;$i<$num;$i++){$list_product_id[]=$obj['json_list'][$i]['product_id'];$list_product_number[]=$obj['json_list'][$i]['product_number'];$insert_order_product_sql='INSERT INTO tbl_order_product (order_id,product_id,product_number) VALUES (?,?,?)';$result = $sqlconn -> prepare($insert_order_product_sql);$result -> bind_param('sss', $order_id,$list_product_id[$i],$list_product_number[$i]);$result->execute();}//--添加訂單信息$insert_order_sql='INSERT INTO tbl_order (order_id,buyer_id,seller_id,all_price) VALUES (?,?,?,?)';$result=$sqlconn->prepare($insert_order_sql);$result->bind_param('ssss',$order_id,$buyer_id,$seller_id,$all_price);$result->execute();$result -> close();$sqlconn -> close();?>

投稿者信息

昵稱: Hola

Email: jamcistos@outlook.com

blog: holajelly.cc

標(biāo)簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 兴文县| 华蓥市| 澎湖县| 庆阳市| 宝坻区| 板桥市| 定西市| 洪泽县| 兴国县| 龙海市| 昌江| 塔城市| 赣州市| 融水| 平湖市| 柘城县| 冀州市| 沙洋县| 准格尔旗| 荃湾区| 三门县| 武宣县| 屏东市| 巴彦淖尔市| 岐山县| 元江| 运城市| 邳州市| 西平县| 宁阳县| 名山县| 康定县| 时尚| 陇南市| 新龙县| 嘉定区| 邯郸市| 康定县| 原平市| 贵阳市| 民县|