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

$nama  = $_POST['nama_petugas'];
$user  = $_POST['username'];
$pass  = $_POST['password'];
$telp  = $_POST['telp'];
$level = $_POST['level'];
$id    = $_POST['id_petugas'];

// Gunakan prepared statement untuk update
$stmt = $conn->prepare("UPDATE petugas SET nama_petugas = ?, username = ?, password = ?, telp = ?, level = ? WHERE id_petugas = ?");
$stmt->bind_param("sssssi", $nama, $user, $pass, $telp, $level, $id);

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

$stmt->close();
$conn->close();
?>
