<?php
include 'session_check.php';
include 'config/db.php';

$id = $_GET['id'];
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['hasil_lab'])) {
    $target = "uploads/" . basename($_FILES['hasil_lab']['name']);
    if (move_uploaded_file($_FILES['hasil_lab']['tmp_name'], $target)) {
        mysqli_query($conn, "UPDATE pasien SET hasil_lab='$target' WHERE id=$id");
        header("Location: view.php?id=$id");
        exit;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Upload Hasil Lab</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body class="bg-light">
<div class="container mt-4">
    <h4>Upload Hasil Lab</h4>
    <form method="post" enctype="multipart/form-data">
        <div class="mb-3">
            <input type="file" name="hasil_lab" class="form-control" required>
        </div>
        <button class="btn btn-primary">Upload</button>
        <a href="view.php?id=<?= $id ?>" class="btn btn-secondary">Kembali</a>
    </form>
</div>
</body>
</html>