From 1a2e0e7d9d1967c02c4f72ad47a1bad6cf69b41f Mon Sep 17 00:00:00 2001 From: Gladys23 Date: Thu, 11 Jun 2026 15:23:09 +0700 Subject: [PATCH] Fix SPBU status writes --- 01/database_01.sql | 19 +++++++++++++++++++ 01/edit.php | 30 ++++++++++++++++++++---------- 01/simpan.php | 33 ++++++++++++++++++++------------- 04/edit.php | 30 ++++++++++++++++++++---------- 04/simpan.php | 33 ++++++++++++++++++++------------- 5 files changed, 99 insertions(+), 46 deletions(-) create mode 100644 01/database_01.sql diff --git a/01/database_01.sql b/01/database_01.sql new file mode 100644 index 0000000..e3db63d --- /dev/null +++ b/01/database_01.sql @@ -0,0 +1,19 @@ +-- Database untuk project 01/04: GIS SPBU +CREATE DATABASE IF NOT EXISTS gis_spbu + CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +USE gis_spbu; + +CREATE TABLE IF NOT EXISTS spbu ( + id INT AUTO_INCREMENT PRIMARY KEY, + nama_spbu VARCHAR(150) NOT NULL, + no_wa VARCHAR(30) NOT NULL, + status ENUM('yes','no') NOT NULL DEFAULT 'no', + latitude DECIMAL(10,8) NOT NULL, + longitude DECIMAL(11,8) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +ALTER TABLE spbu + MODIFY status ENUM('yes','no') NOT NULL DEFAULT 'no'; diff --git a/01/edit.php b/01/edit.php index 54421c2..ed1f605 100644 --- a/01/edit.php +++ b/01/edit.php @@ -1,14 +1,24 @@ query("UPDATE spbu SET -nama_spbu='$nama', -no_wa='$wa', -status='$status' -WHERE id=$id"); -?> \ No newline at end of file +if (!in_array($status, ['yes', 'no'], true)) { + http_response_code(400); + echo "Status tidak valid"; + exit; +} + +try { + $stmt = $conn->prepare("UPDATE spbu SET nama_spbu=?, no_wa=?, status=? WHERE id=?"); + $stmt->bind_param('sssi', $nama, $wa, $status, $id); + $stmt->execute(); + echo "success"; +} catch (mysqli_sql_exception $e) { + http_response_code(500); + echo "error: " . $e->getMessage(); +} +?> diff --git a/01/simpan.php b/01/simpan.php index 6f4a937..eddc551 100644 --- a/01/simpan.php +++ b/01/simpan.php @@ -1,18 +1,25 @@ query($sql)) { - echo "success"; -} else { - echo "error"; +if (!in_array($status, ['yes', 'no'], true)) { + http_response_code(400); + echo "Status tidak valid"; + exit; } -?> \ No newline at end of file + +try { + $stmt = $conn->prepare("INSERT INTO spbu (nama_spbu, no_wa, status, latitude, longitude) VALUES (?, ?, ?, ?, ?)"); + $stmt->bind_param('sssdd', $nama, $wa, $status, $lat, $lng); + $stmt->execute(); + echo "success"; +} catch (mysqli_sql_exception $e) { + http_response_code(500); + echo "error: " . $e->getMessage(); +} +?> diff --git a/04/edit.php b/04/edit.php index 54421c2..ed1f605 100644 --- a/04/edit.php +++ b/04/edit.php @@ -1,14 +1,24 @@ query("UPDATE spbu SET -nama_spbu='$nama', -no_wa='$wa', -status='$status' -WHERE id=$id"); -?> \ No newline at end of file +if (!in_array($status, ['yes', 'no'], true)) { + http_response_code(400); + echo "Status tidak valid"; + exit; +} + +try { + $stmt = $conn->prepare("UPDATE spbu SET nama_spbu=?, no_wa=?, status=? WHERE id=?"); + $stmt->bind_param('sssi', $nama, $wa, $status, $id); + $stmt->execute(); + echo "success"; +} catch (mysqli_sql_exception $e) { + http_response_code(500); + echo "error: " . $e->getMessage(); +} +?> diff --git a/04/simpan.php b/04/simpan.php index 6f4a937..eddc551 100644 --- a/04/simpan.php +++ b/04/simpan.php @@ -1,18 +1,25 @@ query($sql)) { - echo "success"; -} else { - echo "error"; +if (!in_array($status, ['yes', 'no'], true)) { + http_response_code(400); + echo "Status tidak valid"; + exit; } -?> \ No newline at end of file + +try { + $stmt = $conn->prepare("INSERT INTO spbu (nama_spbu, no_wa, status, latitude, longitude) VALUES (?, ?, ?, ?, ?)"); + $stmt->bind_param('sssdd', $nama, $wa, $status, $lat, $lng); + $stmt->execute(); + echo "success"; +} catch (mysqli_sql_exception $e) { + http_response_code(500); + echo "error: " . $e->getMessage(); +} +?>