Fix trailing whitespace and JSON parse errors on backend
This commit is contained in:
+7
-4
@@ -5,9 +5,12 @@ $data = [];
|
||||
|
||||
$result = $conn->query("SELECT * FROM spbu");
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
}
|
||||
} else {
|
||||
// If table doesn't exist or other error, return empty array
|
||||
}
|
||||
|
||||
echo json_encode($data);
|
||||
?>
|
||||
echo json_encode($data);
|
||||
+1
-2
@@ -10,6 +10,5 @@ $query = "DELETE FROM spbu WHERE id='$id'";
|
||||
if ($conn->query($query)) {
|
||||
echo "success";
|
||||
} else {
|
||||
echo "error";
|
||||
echo "error: " . $conn->error;
|
||||
}
|
||||
?>
|
||||
|
||||
+4
-4
@@ -266,7 +266,7 @@ lng:pos.lng
|
||||
})
|
||||
.then(r=>r.text())
|
||||
.then(res=>{
|
||||
if(res=="success"){
|
||||
if(res.trim()=="success"){
|
||||
alert("Lokasi berhasil diupdate");
|
||||
location.reload();
|
||||
}
|
||||
@@ -348,7 +348,7 @@ body:fd
|
||||
})
|
||||
.then(r=>r.text())
|
||||
.then(res=>{
|
||||
if(res=="success"){
|
||||
if(res.trim()=="success"){
|
||||
alert("Data berhasil disimpan");
|
||||
location.reload();
|
||||
}else{
|
||||
@@ -422,7 +422,7 @@ lng:lng
|
||||
})
|
||||
.then(r=>r.text())
|
||||
.then(res=>{
|
||||
if(res=="success"){
|
||||
if(res.trim()=="success"){
|
||||
alert("Data berhasil diupdate");
|
||||
location.reload();
|
||||
}else{
|
||||
@@ -452,7 +452,7 @@ id:id
|
||||
})
|
||||
.then(r=>r.text())
|
||||
.then(res=>{
|
||||
if(res=="success"){
|
||||
if(res.trim()=="success"){
|
||||
alert("Data berhasil dihapus");
|
||||
location.reload();
|
||||
}
|
||||
|
||||
@@ -9,4 +9,3 @@ $conn = mysqli_connect($host, $user, $pass, $db);
|
||||
if (!$conn) {
|
||||
die("Koneksi database gagal: " . mysqli_connect_error());
|
||||
}
|
||||
?>
|
||||
|
||||
+1
-2
@@ -15,6 +15,5 @@ $query = "INSERT INTO spbu (nama_spbu, no_wa, status, latitude, longitude)
|
||||
if ($conn->query($query)) {
|
||||
echo "success";
|
||||
} else {
|
||||
echo "error";
|
||||
echo "error: " . $conn->error;
|
||||
}
|
||||
?>
|
||||
|
||||
+1
-2
@@ -21,6 +21,5 @@ $query = "UPDATE spbu SET
|
||||
if ($conn->query($query)) {
|
||||
echo "success";
|
||||
} else {
|
||||
echo "error";
|
||||
echo "error: " . $conn->error;
|
||||
}
|
||||
?>
|
||||
|
||||
+3
-3
@@ -40,11 +40,11 @@ function importSql($conn, $file) {
|
||||
|
||||
// Cek apakah tabel uas_06 sudah ada (menggunakan tabel role sebagai patokan)
|
||||
$res = $conn->query("SHOW TABLES LIKE 'role'");
|
||||
if ($res->num_rows == 0) {
|
||||
if ($res && $res->num_rows == 0) {
|
||||
echo "Tabel utama (05) belum ada, menjalankan import...\n";
|
||||
importSql($conn, __DIR__ . '/05/database_uas_06.sql');
|
||||
} else {
|
||||
echo "Tabel utama (05) sudah ada, skip import.\n";
|
||||
echo "Tabel utama (05) sudah ada atau query gagal, skip import.\n";
|
||||
}
|
||||
|
||||
// Cek tabel SPBU (04)
|
||||
@@ -52,7 +52,7 @@ $db04 = getenv('DB_NAME_04') ?: $db;
|
||||
$conn->query("CREATE DATABASE IF NOT EXISTS `$db04` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||
$conn->select_db($db04);
|
||||
$res = $conn->query("SHOW TABLES LIKE 'spbu'");
|
||||
if ($res->num_rows == 0) {
|
||||
if ($res && $res->num_rows == 0) {
|
||||
echo "Tabel spbu (04) belum ada, menjalankan import...\n";
|
||||
importSql($conn, __DIR__ . '/04/db_spbu.sql');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user