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

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

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

    if (mysqli_num_rows($result) > 0) {
        echo "Duplicate entry found: Bank name already exists.";
    } else {
        $query = "UPDATE bank SET b_name = '$b_name' WHERE id = '$id'";

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