prepare( 'INSERT INTO donors (full_name, email, phone, blood_type, organs_to_donate, medical_history, password_hash) VALUES (?, ?, ?, ?, ?, ?, ?)' ); $stmt->execute([$full_name, $email, $phone, $blood_type, $organs_to_donate, $medical_history, $password_hash]); $donor_id = db()->lastInsertId(); $_SESSION['user_id'] = $donor_id; $_SESSION['user_type'] = 'donor'; $_SESSION['user_email'] = $email; header("Location: dashboard.php"); exit; } catch (PDOException $e) { if ($e->getCode() == 23000) { // Integrity constraint violation (duplicate entry) $error_message = "The email address you entered is already registered."; } else { $error_message = "An error occurred while processing your request. Please try again later."; } } catch (Exception $e) { $error_message = $e->getMessage(); } } ?>