<?php
include_once '../config/connect.php';

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['delete_bank'])) {
    
    $id = $_POST['id'] ?? '';

    if (!ctype_digit($id)) {
        header('Location: ../Settings?msg=39');
        exit();
    }

    $id = mysqli_real_escape_string($call, $id);

    $check_query = "SELECT id FROM tb_billing WHERE id = '$id'";
    $check_result = mysqli_query($call, $check_query);
    
    if (mysqli_num_rows($check_result) == 0) {
        header('Location: ../Settings?msg=47');
        exit();
    }

    $query = "DELETE FROM tb_billing WHERE id = '$id'";
    $result = mysqli_query($call, $query);

    if ($result) {
        header('Location: ../Settings?msg=46');
        exit();
    } else {
        header('Location: ../Settings?msg=13');
        exit();
    }
}
?>
