updated validation of json
This commit is contained in:
parent
4b864cc658
commit
3e7d64b782
@ -32,7 +32,7 @@ foreach ($jsonEntries as $entry) {
|
||||
// Validate and insert product
|
||||
$productId = insertProduct($data['product'], $pdo);
|
||||
|
||||
if ($productId) {
|
||||
if ($productId && validateJson($data)) {
|
||||
// Insert reports, parts, analyses, and results
|
||||
foreach ($data['product']['reports'] as $report) {
|
||||
$reportId = insertReport($report, $productId, $labId, $pdo);
|
||||
@ -58,6 +58,15 @@ foreach ($jsonEntries as $entry) {
|
||||
|
||||
// Function definitions
|
||||
|
||||
function validateJson($json){
|
||||
$checkData = json_encode($json);
|
||||
if(json_decode($checkData) !== null){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getLaboratoryId($reflab, $pdo) {
|
||||
$query = "SELECT idlab FROM laboratories WHERE reflab = :reflab";
|
||||
$stmt = $pdo->prepare($query);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user