36694-vm/hospital_registration.php
Flatlogic Bot c12628e2d9 v2
2025-12-05 21:07:12 +00:00

131 lines
6.1 KiB
PHP

<?php
require_once 'db/config.php';
$page_title = "Hospital Registration";
$error_message = '';
$success_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$address = trim($_POST['address']);
$password = $_POST['password'];
$password_confirm = $_POST['password_confirm'];
if (empty($name) || empty($email) || empty($password)) {
$error_message = "Please fill in all required fields (Name, Email, Password).";
} elseif ($password !== $password_confirm) {
$error_message = "Passwords do not match.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = "Invalid email format.";
} else {
try {
$pdo = db();
// Check if email already exists
$stmt = $pdo->prepare("SELECT id FROM hospitals WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$error_message = "A hospital with this email is already registered.";
} else {
$hashed_password = password_hash($password, PASSWORD_BCRYPT);
$sql = "INSERT INTO hospitals (name, email, phone, address, password) VALUES (?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $email, $phone, $address, $hashed_password]);
$hospital_id = $pdo->lastInsertId();
$_SESSION['user_id'] = $hospital_id;
$_SESSION['user_type'] = 'hospital';
$_SESSION['user_email'] = $email;
header("Location: dashboard.php");
exit;
}
} catch (PDOException $e) {
$error_message = "Database error: " . $e->getMessage();
// In a real application, you would log this error, not show it to the user
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - Organ Donation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="index.php">Home</a>
<a class="nav-link text-white" href="donor_registration.php">Donor Registration</a>
<a class="nav-link text-white active" href="hospital_registration.php">Hospital Registration</a>
<a class="nav-link text-white" href="login.php">Login</a>
</nav>
</div>
</header>
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h2 class="h4 mb-0"><?= htmlspecialchars($page_title) ?></h2>
</div>
<div class="card-body">
<?php if ($success_message): ?>
<div class="alert alert-success"><?= htmlspecialchars($success_message) ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error_message) ?></div>
<?php endif; ?>
<form action="hospital_registration.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Hospital Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone Number</label>
<input type="tel" class="form-control" id="phone" name="phone">
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<textarea class="form-control" id="address" name="address" rows="3"></textarea>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="password_confirm" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Register</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>