This commit is contained in:
2025-11-27 22:25:36 +00:00
commit c1667681e7
117 changed files with 91960 additions and 0 deletions

41
update_field.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
// Connecting, selecting database
$dbconn = pg_connect("host=localhost dbname=nws user=nws password=nws")
or die('Could not connect: ' . pg_last_error());
// Get POST data
$camid = $_POST['camid'];
$field = $_POST['field'];
$value = $_POST['value'];
// Validate inputs
if (empty($camid) || empty($field)) {
echo json_encode(['success' => false, 'message' => 'Invalid input']);
exit;
}
// Check if the field is valid
if (!in_array($field, ['hydro', 'airport'])) {
echo json_encode(['success' => false, 'message' => 'Invalid field']);
exit;
}
// Convert to proper boolean for PostgreSQL
// JavaScript sends true/false as strings 'true' or 'false'
$value_bool = ($value === 'true');
// Update the field value in the database - use boolean directly
// PostgreSQL accepts 't'/'f' for boolean values
$query = "UPDATE cams SET $field = $1 WHERE camid = $2";
$result = pg_query_params($dbconn, $query, array($value_bool ? 't' : 'f', $camid));
if ($result) {
echo json_encode(['success' => true]);
} else {
$error = pg_last_error($dbconn);
echo json_encode(['success' => false, 'message' => $error]);
}
// Closing connection
pg_close($dbconn);
?>