<?php
include 'koneksi.php';

header('Content-Type: text/plain; charset=utf-8');

$nama   = mysqli_real_escape_string($koneksi, $_POST['nama_spbu'] ?? '');
$wa     = mysqli_real_escape_string($koneksi, $_POST['no_wa'] ?? '');
$status = mysqli_real_escape_string($koneksi, $_POST['status_24_jam'] ?? 'no');
$lat    = floatval($_POST['lat'] ?? 0);
$lng    = floatval($_POST['lng'] ?? 0);

if (!$nama || !$wa) {
    echo "Gagal: Nama dan nomor WA wajib diisi!";
    exit;
}

$query = "INSERT INTO `$nama_tabel` (nama_spbu, no_wa, status_24_jam, lat, lng) 
          VALUES ('$nama', '$wa', '$status', '$lat', '$lng')";

if (mysqli_query($koneksi, $query)) {
    echo "Data SPBU berhasil ditambahkan!";
} else {
    echo "Gagal menambahkan data: " . mysqli_error($koneksi);
}
?>
