Forum Moderators: coopster
$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'];
echo "This is the input received...";
//add true for associative array...
$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]); Since my schema has a number of JSON tables, I want the ID to be the key for the array as an added layer of protection against inserting the wrong data in the wrong place.
echo 'Here is our new JSON';
print_r($json);
$sql= "INSERT INTO vehicle (OilChange) VALUES (JSON_OBJECT($json))";
$result=mysqli_query($ms, $sql);
if(!$result)
{
echo 'Oil Change Not Inserted! '. mysqli_error($ms);
}
else
{
echo "Oil Change Inserted!";
}