<?php
include "config.php"; // Ensure this connects to your DB

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $id     = mysqli_real_escape_string($con, $_POST['id']);
    $n_name = mysqli_real_escape_string($con, $_POST['n_name']);

    // Check for duplicate name (excluding current id)
    $checkQuery = "SELECT * FROM notice WHERE n_name = '$n_name' AND id != '$id'";
    $result = mysqli_query($con, $checkQuery);

    if (mysqli_num_rows($result) > 0) {
        echo "Duplicate entry found: Notice name already exists.";
    } else {
        $updateQuery = "UPDATE notice SET n_name = '$n_name' WHERE id = '$id'";

        if (mysqli_query($con, $updateQuery)) {
                                                    echo '<script>window.location.href = "notice.php";</script>';
            exit();
        } else {
            echo "Error updating notice: " . mysqli_error($con);
        }
    }
}
?>