php接收數(shù)據(jù)代碼 php接收數(shù)據(jù)的方法

PHP怎么接收數(shù)據(jù)

三中接受方式:

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了新華免費(fèi)建站歡迎大家使用!

$_GET ? ?//get過來的數(shù)據(jù)

$_POST ?//post過來的數(shù)據(jù)

file_get_contents("php://input") ? //接口過來的xml等字符串?dāng)?shù)據(jù)用這個(gè)接

這三個(gè)方法足以接受任何數(shù)據(jù)了,具體你還要百度一下用法

php接收POST數(shù)據(jù)并循環(huán)輸出的代碼

在php中,表單POST提交的數(shù)據(jù)是存放在$_POST變量中.$_POST變量是一個(gè)數(shù)組,它是一個(gè)以表單字段名作索引的數(shù)組.比如有以下表單:

form?method="post"

p姓名:input?type="text"?name="name"?value=""/p

p年齡:input?type="text"?name="age"?value=""/p

pinput?type="submit"?value="提交"/p

/form

輸入值后提交,按你的要求,在php層處理輸出提交的內(nèi)容,那么可以這樣:

?php

echo?'你的姓名是:'.$_POST['name'];//其中$_POST['name']中存放的是上面表單名為name的值

echo?'你今年'.$_POST['age'].'歲';//其中$_POST['age']中存放的是上面表單名為age的值

?

如果字段內(nèi)容很多,有時(shí)就可能需要循環(huán)處理.

foreach($_POST?as?$val){

echo?$val;

}

或直接:

print_r($_POST);

當(dāng)然處理或輸出的格式很多,以上只是一個(gè)示例.

PHP接收json 并將接收數(shù)據(jù)插入數(shù)據(jù)庫的實(shí)現(xiàn)代碼

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

難點(diǎn)

1、php解析json(這個(gè)不算難點(diǎn)了,網(wǎng)上實(shí)例一抓一大把)

2、解析json后,php怎樣拿到該拿的值

?php

require

('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,獲取對(duì)應(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ù)組長(zhǎng)度

$num=count($obj["json_list"]);

//--遍歷數(shù)組,將對(duì)應(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

文章題目:php接收數(shù)據(jù)代碼 php接收數(shù)據(jù)的方法
網(wǎng)站URL:http://muchs.cn/article38/docsdsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化虛擬主機(jī)、網(wǎng)站營(yíng)銷、ChatGPT、定制網(wǎng)站云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)