34981-vm/patient-registration.php
Flatlogic Bot e59c8581a5 1.0.1
2025-10-15 18:48:09 +00:00

197 lines
9.3 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$pdo = db();
// Create table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS patients (
id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
dob DATE,
passport_id_path VARCHAR(255),
contact_number VARCHAR(50),
emergency_contact VARCHAR(50),
medical_history TEXT,
insurance_info VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
// File upload handling
$passport_id_path = null;
if (isset($_FILES['passportId']) && $_FILES['passportId']['error'] == UPLOAD_ERR_OK) {
$upload_dir = 'uploads/passports/';
$file_name = uniqid() . '-' . basename($_FILES['passportId']['name']);
$passport_id_path = $upload_dir . $file_name;
if (!move_uploaded_file($_FILES['passportId']['tmp_name'], $passport_id_path)) {
throw new Exception("Failed to upload passport/ID file.");
}
}
// Hash password
$password_hash = password_hash($_POST['password'], PASSWORD_DEFAULT);
// Insert data
$stmt = $pdo->prepare(
"INSERT INTO patients (full_name, email, password, dob, passport_id_path, contact_number, emergency_contact, medical_history, insurance_info)
VALUES (:full_name, :email, :password, :dob, :passport_id_path, :contact_number, :emergency_contact, :medical_history, :insurance_info)"
);
$stmt->bindParam(':full_name', $_POST['fullName']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password', $password_hash);
$stmt->bindParam(':dob', $_POST['dob']);
$stmt->bindParam(':passport_id_path', $passport_id_path);
$stmt->bindParam(':contact_number', $_POST['contactNumber']);
$stmt->bindParam(':emergency_contact', $_POST['emergencyContact']);
$stmt->bindParam(':medical_history', $_POST['medicalHistory']);
$stmt->bindParam(':insurance_info', $_POST['insuranceInfo']);
$stmt->execute();
$success_message = "Registration successful! You can now log in.";
} catch (PDOException $e) {
if ($e->getCode() == 23000) { // Integrity constraint violation (duplicate entry)
$error_message = "An account with this email address already exists.";
} else {
$error_message = "Database error: " . $e->getMessage();
}
} catch (Exception $e) {
$error_message = "An error occurred: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Patient Registration - Medicaltour</title>
<meta name="description" content="Patient registration for Medicaltour.">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
body {
padding-top: 5rem;
}
</style>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg fixed-top">
<div class="container">
<a class="navbar-brand" href="index.php">Medicaltour</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="index.php#hero">Home</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#portfolio">Services</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#testimonials">Testimonials</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Register
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="patient-registration.php">Patient</a></li>
<li><a class="dropdown-item" href="doctor-registration.php">Doctor</a></li>
<li><a class="dropdown-item" href="hospital-registration.php">Hospital</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="login.php">Login</a></li>
</ul>
</div>
</div>
</nav>
</header>
<main class="container my-5">
<div class="row">
<div class="col-md-8 mx-auto">
<h2 class="text-center mb-4">Patient Registration</h2>
<?php if ($success_message): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<?php if (!$success_message): ?>
<p class="text-center mb-4">Create your account to access our services.</p>
<form action="patient-registration.php" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-6 mb-3">
<label for="fullName" class="form-label">Full Name</label>
<input type="text" class="form-control" id="fullName" name="fullName" required>
</div>
<div class="col-md-6 mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="col-md-6 mb-3">
<label for="dob" class="form-label">Date of Birth</label>
<input type="date" class="form-control" id="dob" name="dob" required>
</div>
</div>
<div class="mb-3">
<label for="passportId" class="form-label">Passport / ID Upload</label>
<input class="form-control" type="file" id="passportId" name="passportId">
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="contactNumber" class="form-label">Contact Number</label>
<input type="tel" class="form-control" id="contactNumber" name="contactNumber">
</div>
<div class="col-md-6 mb-3">
<label for="emergencyContact" class="form-label">Emergency Contact Number</label>
<input type="tel" class="form-control" id="emergencyContact" name="emergencyContact">
</div>
</div>
<div class="mb-3">
<label for="medicalHistory" class="form-label">Basic Medical History</label>
<textarea class="form-control" id="medicalHistory" name="medicalHistory" rows="3"></textarea>
</div>
<div class="mb-3">
<label for="insuranceInfo" class="form-label">Insurance Information</label>
<input type="text" class="form-control" id="insuranceInfo" name="insuranceInfo">
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Register</button>
</div>
</form>
<?php endif; ?>
</div>
</div>
</main>
<footer class="py-4 bg-dark text-white text-center">
<div class="container">
<p>&copy; 2025 Medicaltour. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>