<?php
// deletePatient.php

session_start();
// Line 9
require_once __DIR__ . '/../../dripend/includes/db.php';
// Validate ID
if (!isset($_GET['id']) || empty($_GET['id'])) {
    die("Invalid request.");
}

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

// Optional: Check if record exists first
$stmt = $conn->prepare("SELECT id FROM patient WHERE id=? LIMIT 1");
$stmt->bind_param("i", $id);
$stmt->execute();
$res = $stmt->get_result();

if ($res->num_rows === 0) {
    die("Patient not found.");
}

// DELETE RECORD
$delete = $conn->prepare("DELETE FROM patient WHERE id=?");
$delete->bind_param("i", $id);

if ($delete->execute()) {

    $_SESSION['success'] = "Patient deleted successfully.";

    header("Location: totalPatientReport.php");
    exit;

} else {
    echo "<p style='color:red;'>Delete failed: {$delete->error}</p>";
}
?>