exec(" CREATE TABLE IF NOT EXISTS donors ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, age INT NOT NULL, blood_type VARCHAR(3) NOT NULL, weight_kg FLOAT NOT NULL, phone VARCHAR(20) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, emergency_contact_name VARCHAR(255) NOT NULL, emergency_contact_phone VARCHAR(20) NOT NULL, status VARCHAR(20) DEFAULT 'Pending Verification', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) "); // Validation $required_fields = ['name', 'age', 'blood_type', 'weight_kg', 'phone', 'email', 'emergency_contact_name', 'emergency_contact_phone']; foreach ($required_fields as $field) { if (empty($_POST[$field])) { throw new Exception("All fields are required."); } } if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { throw new Exception("Invalid email format."); } if ($_POST['age'] < 18 || $_POST['age'] > 75) { throw new Exception("Age must be between 18 and 75."); } // Insert data $stmt = $pdo->prepare( "INSERT INTO donors (name, age, blood_type, weight_kg, phone, email, emergency_contact_name, emergency_contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ); $stmt->execute([ $_POST['name'], $_POST['age'], $_POST['blood_type'], $_POST['weight_kg'], $_POST['phone'], $_POST['email'], $_POST['emergency_contact_name'], $_POST['emergency_contact_phone'] ]); $successMessage = "Thank you for registering! Your application is pending verification."; } catch (PDOException $e) { if ($e->errorInfo[1] == 1062) { // Duplicate entry for email $errorMessage = "This email address is already registered."; } else { $errorMessage = "Database error: " . $e->getMessage(); } } catch (Exception $e) { $errorMessage = $e->getMessage(); } } ?> <?= htmlspecialchars($pageTitle) ?> - Organ Donation System

Donor Registration

Complete the form below to become a registered organ donor.


Emergency Contact