<?php

$servername = 'localhost';
$username = 's2300379_g5pharmaease';
$password = '12345';
$dbname = 's2300379_g5pharmaease';

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    if (isset($_GET['id'])) { // Check if 'id' is passed via GET
        $id = $_GET['id'];

        // Prepare and execute the DELETE statement
        $stmt = $conn->prepare("DELETE FROM user_records WHERE ID = :id");
        $stmt->bindParam(':id', $id);
        $stmt->execute();

        header("Location: ../view/admin/dashboard.php"); // Redirect to the dashboard after deletion
        exit();
    } else {
        echo "Error: User ID not provided.";
    }

} catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}

$conn = null; // Close the database connection

?>