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.
109 lines
3.6 KiB
109 lines
3.6 KiB
6 months ago
|
<?php
|
||
|
require 'db_connection.php';
|
||
|
session_start();
|
||
|
|
||
|
// Check if the user is logged in
|
||
|
if (!isset($_SESSION['user_email'])) {
|
||
|
header("Location: login.php");
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Retrieve logged-in user details
|
||
|
$user_email = $_SESSION['user_email'];
|
||
|
$stmt = $conn->prepare("SELECT id, first_name, last_name FROM users WHERE email = ?");
|
||
|
$stmt->bind_param("s", $user_email);
|
||
|
$stmt->execute();
|
||
|
$result = $stmt->get_result();
|
||
|
$user = $result->fetch_assoc();
|
||
|
$user_id = $user['id'];
|
||
|
$stmt->close();
|
||
|
|
||
|
// Handle form submission
|
||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
|
$blood_type = $_POST['blood_type'];
|
||
|
$availability = $_POST['availability'];
|
||
|
$last_donation_date = $_POST['last_donation_date'];
|
||
|
|
||
|
// Validate inputs
|
||
|
if (empty($blood_type) || empty($availability) || empty($last_donation_date)) {
|
||
|
$error_message = "All fields are required.";
|
||
|
} else {
|
||
|
// Insert donor profile into the database
|
||
|
$stmt = $conn->prepare("INSERT INTO blood_donors (donor_id, blood_type, availability, last_donation_date) VALUES (?, ?, ?, ?)");
|
||
|
$stmt->bind_param("isss", $user_id, $blood_type, $availability, $last_donation_date);
|
||
|
|
||
|
if ($stmt->execute()) {
|
||
|
$success_message = "Your donor profile has been created successfully.";
|
||
|
} else {
|
||
|
$error_message = "Failed to create your donor profile. Please try again.";
|
||
|
}
|
||
|
|
||
|
$stmt->close();
|
||
|
}
|
||
|
}
|
||
|
?>
|
||
|
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>Donor Profile</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>Create Donor Profile</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="donor_profile.php">
|
||
|
<div class="mb-3">
|
||
|
<label for="blood_type" class="form-label">Blood Type</label>
|
||
|
<select name="blood_type" id="blood_type" class="form-select" required>
|
||
|
<option value="">Select Blood Type</option>
|
||
|
<option value="A+">A+</option>
|
||
|
<option value="A-">A-</option>
|
||
|
<option value="B+">B+</option>
|
||
|
<option value="B-">B-</option>
|
||
|
<option value="O+">O+</option>
|
||
|
<option value="O-">O-</option>
|
||
|
<option value="AB+">AB+</option>
|
||
|
<option value="AB-">AB-</option>
|
||
|
</select>
|
||
|
</div>
|
||
|
|
||
|
<div class="mb-3">
|
||
|
<label for="availability" class="form-label">Availability</label>
|
||
|
<textarea name="availability" id="availability" class="form-control" rows="3" required></textarea>
|
||
|
</div>
|
||
|
|
||
|
<div class="mb-3">
|
||
|
<label for="last_donation_date" class="form-label">Last Donation Date</label>
|
||
|
<input type="date" name="last_donation_date" id="last_donation_date" class="form-control" required>
|
||
|
</div>
|
||
|
|
||
|
<button type="submit" class="btn btn-primary">Create Profile</button>
|
||
|
</form>
|
||
|
</div>
|
||
|
|
||
|
<?php include 'includes/footer.php'; ?>
|
||
|
</body>
|
||
|
|
||
|
</html>
|