exec("CREATE TABLE IF NOT EXISTS donors ( id INT AUTO_INCREMENT PRIMARY KEY, full_name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, phone VARCHAR(50), blood_type VARCHAR(10), organs_to_donate TEXT, registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, status VARCHAR(50) DEFAULT 'pending_verification' )"); } catch (PDOException $e) { $error_message = "Database error: " . $e->getMessage(); } if ($_SERVER["REQUEST_METHOD"] == "POST") { $full_name = trim($_POST['full_name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $blood_type = $_POST['blood_type']; $organs = isset($_POST['organs']) ? implode(', ', $_POST['organs']) : ''; if (empty($full_name) || empty($email) || empty($blood_type) || empty($organs)) { $error_message = "Please fill all required fields."; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error_message = "Invalid email format."; } else { try { $stmt = $pdo->prepare("INSERT INTO donors (full_name, email, phone, blood_type, organs_to_donate) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$full_name, $email, $phone, $blood_type, $organs]); $success_message = "Thank you for registering as a donor! Your registration is pending verification."; } catch (PDOException $e) { if ($e->getCode() == 23000) { // Integrity constraint violation (e.g., duplicate email) $error_message = "This email address is already registered."; } else { $error_message = "There was an error with your registration. Please try again."; } } } } ?>