menambahkan fitur edit data pengguna dan memperbarui landing page
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require_once '../../auth.php';
|
||||
requireRole('admin');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$conn = new mysqli("localhost", "root", "", "webgis");
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$id = (int) $data['id'];
|
||||
|
||||
// Tidak boleh hapus diri sendiri
|
||||
if ($id === (int) $_SESSION['user']) {
|
||||
echo json_encode(["status" => "error", "message" => "Tidak bisa menghapus akun sendiri"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => $stmt->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user