57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
<?php
|
|
// proses.php
|
|
$conn = new mysqli("localhost", "root", "", "db_tugas_1_sig"); // Sesuaikan nama DB kamu
|
|
|
|
if ($conn->connect_error) {
|
|
die("Koneksi gagal: " . $conn->connect_error);
|
|
}
|
|
|
|
$action = isset($_GET['action']) ? $_GET['action'] : (isset($_POST['action']) ? $_POST['action'] : '');
|
|
|
|
// --- PROSES SIMPAN DATA (CREATE) ---
|
|
if ($action == 'create' && $_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$type = $_POST['type'];
|
|
$nama_atribut = $_POST['nama_atribut'];
|
|
$status = $_POST['status'];
|
|
$geojson = $_POST['geojson'];
|
|
|
|
// Ambil string input (Contoh: "1500.50 Meter" atau "300.45 m²")
|
|
$mentah = $_POST['hasil_hitung'];
|
|
|
|
// Gunakan regex untuk mengambil angka dan desimalnya saja agar aman masuk ke kolom FLOAT
|
|
preg_match('/[0-9.]+/', $mentah, $matches);
|
|
$angka_murni = isset($matches[0]) ? floatval($matches[0]) : 0;
|
|
|
|
if ($type == 'jalan') {
|
|
$sql = "INSERT INTO data_jalan (nama_jalan, status_jalan, panjang_meter, geojson)
|
|
VALUES ('$nama_atribut', '$status', '$angka_murni', '$geojson')";
|
|
} else if ($type == 'parsil') {
|
|
$sql = "INSERT INTO data_parsil (kode_kavling, status_kepemilikan, luas_meter, geojson)
|
|
VALUES ('$nama_atribut', '$status', '$angka_murni', '$geojson')";
|
|
}
|
|
|
|
if ($conn->query($sql) === TRUE) {
|
|
echo "<script>alert('Data Berhasil Disimpan!'); window.location='index.php';</script>";
|
|
} else {
|
|
echo "Error: " . $sql . "<br>" . $conn->error;
|
|
}
|
|
}
|
|
|
|
// --- PROSES HAPUS DATA (DELETE) ---
|
|
if ($action == 'delete' && isset($_GET['id']) && isset($_GET['type'])) {
|
|
$id = intval($_GET['id']);
|
|
$type = $_GET['type'];
|
|
|
|
if ($type == 'jalan') {
|
|
$sql = "DELETE FROM data_jalan WHERE id = $id";
|
|
} else if ($type == 'parsil') {
|
|
$sql = "DELETE FROM data_parsil WHERE id = $id";
|
|
}
|
|
|
|
if ($conn->query($sql) === TRUE) {
|
|
echo "<script>alert('Data Berhasil Dihapus!'); window.location='index.php';</script>";
|
|
}
|
|
}
|
|
|
|
$conn->close();
|
|
?>
|