prepare("SELECT UniverseID FROM assets WHERE AssetID = :assetId AND AssetType = 9"); $stmt->bindParam(':assetId', $pid); $stmt->execute(); $pid = $stmt->fetchColumn(); if (startsWith($_POST["value"], "[{") && endsWith($_POST["value"], "}]")){ $postData = json_decode($_POST["value"]); if (count($postData) == 1){ if (isset($postData['0']->Scope) && isset($postData['0']->Key) && isset($postData['0']->Value)){ $_POST["value"] = $postData['0']->Value; } } } $query = "INSERT INTO `datastores`(`id`, `key`, `universeId`, `type`, `scope`, `target`, `value`) VALUES (NULL,:key,:pid,:type,:scope,:target,:val)"; $queryChanged=false; $where = "WHERE `universeId`=:pid AND `scope`=:scope AND `type`=:type AND `key`=:key AND `target`=:target"; $stmt = $pdo->prepare("SELECT * FROM `datastores` $where"); $stmt->bindParam(':key', $key, PDO::PARAM_STR); $stmt->bindParam(':pid', $pid, PDO::PARAM_INT); $stmt->bindParam(':scope', $scope, PDO::PARAM_STR); $stmt->bindParam(':type', $type, PDO::PARAM_STR); $stmt->bindParam(':target', $target, PDO::PARAM_STR); $stmt->execute(); if($stmt->rowCount()>0){ $query = "UPDATE `datastores` SET `value`=:val $where"; } $stmt = $pdo->prepare($query); $stmt->bindParam(':key', $key, PDO::PARAM_STR); $stmt->bindParam(':pid', $pid, PDO::PARAM_INT); $stmt->bindParam(':scope', $scope, PDO::PARAM_STR); $stmt->bindParam(':type', $type, PDO::PARAM_STR); $stmt->bindParam(':target', $target, PDO::PARAM_STR); $stmt->bindParam(':val', $_POST["value"]); $stmt->execute(); $values = [array("Value"=>$_POST["value"],"Scope"=>$scope,"Key"=>$key,"Target"=>$target)]; exit(json_encode(["data"=>$_POST["value"]], JSON_NUMERIC_CHECK)); } error_log("failed you bastard"); exit(json_encode(["error"=>"fail"])); ?>