getMessage(); exit; // stop further execution because of the error } // Check if all the expected POST data is available if (isset($_POST['levelId'], $_POST['selectName'], $_POST['selectedValue'])) { $levelId = $_POST['levelId']; $selectName = $_POST['selectName']; $selectedValue = $_POST['selectedValue']; // Update the data in the levels table $query = "UPDATE levels SET $selectName = :selectedValue WHERE Id = :levelId"; $params = [ ':selectedValue' => $selectedValue, ':levelId' => $levelId ]; // Execute the query using the PDO_Execute() function $result = PDO_Execute($query, $params); if ($result) { echo json_encode(['status' => 'success', 'message' => 'Data updated successfully.']); } else { echo json_encode(['status' => 'error', 'message' => 'Failed to update data.']); } } else { echo json_encode(['status' => 'error', 'message' => 'Invalid POST data.']); } //$tsvFileName = "Levels"; //$db = new SQLite3(DB_FILE); //$message = writeToTsvFile($tsvFileName, $db); // //echo $message; $bin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? getcwd() . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "sqlite3.exe" : "/usr/bin/sqlite3"; $dbfile = DB_FILE; $tablename = "levels"; $outputFile = $_SESSION['path'] . "Levels.txt"; // Build the command to export the SQLite table to a TSV file $command = sprintf( '%s %s ".mode tabs" ".headers on" "SELECT * FROM %s;" > "%s"', $bin, $dbfile, $tablename, $outputFile ); //ddump($command); // Execute the command $commandOutput = shell_exec($command); if ($commandOutput) { echo "Error: $commandOutput"; } else { echo "Table exported successfully!"; }