diff --git a/plt/index.php b/plt/index.php index e160364..8f7e3c3 100755 --- a/plt/index.php +++ b/plt/index.php @@ -182,7 +182,8 @@ function runJavascriptCodeTrigger($functionName, $activeTable, $row) { function updateDatabaseRow($tableName, $originalRow, $newRowValue) { if (empty($originalRow) || empty($newRowValue)) return; $pkColsName = getTblPrimaryKeyColName($tableName); - $pkColsValues = array_map(fn($cName) => $originalRow[$cName], $pkColsName); + if (empty($pkColsName)) {echo redText("ERROR: No PRIMARY KEY foudn for table: $tableName\n"); return;} + $pkColsValues = array_map(fn($cName) => $originalRow[$cName], $pkColsName); $setStatements = []; foreach ($newRowValue as $k => $v) { @@ -194,12 +195,12 @@ function updateDatabaseRow($tableName, $originalRow, $newRowValue) { foreach ($pkColsName as $k) { $val = is_numeric($originalRow[$k]) ? $originalRow[$k] : "'" . $originalRow[$k] . "'"; $whereStatements[] = "$k = $val"; - } + } $sql_instruction = "UPDATE $tableName SET " . implode(", ", $setStatements) . " WHERE " . implode(" AND ", $whereStatements); try {sql($sql_instruction);} catch (Exception $e) { - echo "ERROR: while trying $sql_instruction\n\n";print_r($e->getMessage()); + echo redText("ERROR: while trying $sql_instruction\n\n");print_r($e->getMessage()); } }