<?php
include "db.php";

// Check if ID is provided
if(!isset($_GET['id'])) {
    echo "<p style='color:red;'>No Customer ID provided.</p>";
    exit;
}

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

// Delete customer
$sql = "DELETE FROM customers WHERE id = $id";
if($conn->query($sql)){
    echo "<p style='color:green;'>Customer deleted successfully!</p>";
    echo "<script>
        // Redirect back to customers list after 1.5 seconds
        setTimeout(function(){
            window.location.href='customers_view.php';
        }, 1500);
    </script>";
} else {
    echo "<p style='color:red;'>Error deleting customer: " . $conn->error . "</p>";
}
?>
