<?php
require '../koneksi.php';

$nama   = $_POST['nama'];
$user   = $_POST['username'];
$pass   = $_POST['password'];
$telp   = $_POST['telp'];
$nik    = $_POST['nik'];

// Gunakan prepared statement
$stmt = $conn->prepare("UPDATE masyarakat SET nama = ?, username = ?, password = ?, telp = ? WHERE nik = ?");
$stmt->bind_param("sssss", $nama, $user, $pass, $telp, $nik);

if ($stmt->execute()) {
    echo "<script>
        alert('Data Berhasil Diubah');
        window.location='admin.php?url=lihat_masyarakat';
    </script>";
} else {
    echo "<script>
        alert('Gagal mengubah data: " . $stmt->error . "');
        window.history.back();
    </script>";
}

// Tutup koneksi
$stmt->close();
$conn->close();
?>
