gpt4 book ai didi

php - 使用php将Json数据以json数据类型插入mysql数据库

转载 作者:行者123 更新时间:2023-11-29 16:50:26 25 4
gpt4 key购买 nike

我有来自 UNITY3d WWWForm 的表单数据到我的 php 文件。我用 json 文件类型创建了一个列,现在我想将该字符串存储在数据库中。我还希望 id 字段成为数组其余部分的键。

include('dbconfig.php');

$id= $_POST['ID'];
$servicedate=$_POST['ServiceDate'];
$servicelocation=$_POST['ServiceLocation'];
$mileage=$_POST['Mileage'];
$labor=$_POST['Labor'];
$oilbrand=$_POST['OilBrand'];
$oilprice=$_POST['OilPrice'];
$filterbrand=$_POST['FilterBrand'];
$filterprice=$_POST['FilterPrice'];
$oilfilterpurchaselocation=$_POST['PurchasePlace'];


$arr = array('Service Date' => $servicedate,
'Service Location' => $servicelocation,
'Mileage' => $mileage,
'Labor' => $labor,
'Oil Brand' => $oilbrand,
'Oil Price' => $oilprice,
'Filter Brand' => $filterbrand ,
'Filter Price' => $filterprice ,
'Purchase Place' =>$oilfilterpurchaselocation);
$json= json_encode($id => $arr); //Is this part right?
echo 'Here is our new JSON';
echo $json;

$var= $db->prepare("INSERT into json VALUES(?,?,?,?,?)";
foreach($data as $row)
{
$var->bindParam(1, $row['id']);
$var->bindParam(2, $row['']);
$var->bindParam(3, $row['']);
$var->execute();
}

这更符合我的需要吗?谢谢!

最佳答案

您的所有数据都传入数组$arr,您可以简单地使用此代码。

$json= json_encode($arr); 

不要使用 echo 检查 print_r($json) 中的 json 数据;

关于php - 使用php将Json数据以json数据类型插入mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52841960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com