<?php
session_start();

// proteksi: harus login
if (!isset($_SESSION['login'])) {
    header("Location: login.php");
    exit;
}

require 'koneksi.php';

// validasi parameter
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header("Location: kontak.php");
    exit;
}

$id = intval($_GET['id']);

// hapus data
$query = mysqli_query($conn, "DELETE FROM kontak WHERE id = $id");

if ($query) {
    header("Location: kontak.php?hapus=berhasil");
} else {
    die("Gagal menghapus data: " . mysqli_error($conn));
}
