You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
FutureCraft/schedule_appointment.php

77 lines
2.4 KiB

<?php
require 'db_connection.php';
session_start();
// Check if the user is logged in
if (!isset($_SESSION['user_email'])) {
header("Location: login.php");
exit;
}
// Handle scheduling
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$donor_id = $_SESSION['user_id']; // Assumed session variable to store logged-in user ID
$hospital_name = $_POST['hospital_name'];
$appointment_date = $_POST['appointment_date'];
// Insert appointment
$stmt = $conn->prepare("INSERT INTO appointments (donor_id, hospital_name, appointment_date) VALUES (?, ?, ?)");
$stmt->bind_param("iss", $donor_id, $hospital_name, $appointment_date);
if ($stmt->execute()) {
$success_message = "Appointment scheduled successfully.";
} else {
$error_message = "Failed to schedule the appointment.";
}
$stmt->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Schedule Appointment</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<?php include 'includes/header.php'; ?>
<div class="container mt-4">
<h2>Schedule Blood Donation Appointment</h2>
<!-- Display success or error messages -->
<?php if (isset($success_message)): ?>
<div class="alert alert-success">
<?php echo $success_message; ?>
</div>
<?php endif; ?>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger">
<?php echo $error_message; ?>
</div>
<?php endif; ?>
<form method="POST" action="schedule_appointment.php">
<div class="mb-3">
<label for="hospital_name" class="form-label">Hospital Name</label>
<input type="text" name="hospital_name" id="hospital_name" class="form-control" required>
</div>
<div class="mb-3">
<label for="appointment_date" class="form-label">Appointment Date and Time</label>
<input type="datetime-local" name="appointment_date" id="appointment_date" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary">Schedule Appointment</button>
</form>
</div>
<?php include 'includes/footer.php'; ?>
</body>
</html>