Doctor Registration
Join our network of trusted medical professionals.
query("SELECT id, hospital_name as name FROM hospitals ORDER BY name"); $hospitals = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { // If hospitals table doesn't exist, we can proceed without it if ($e->getCode() !== '42S02') { $error_message = "Database error: " . $e->getMessage(); } } if ($_SERVER["REQUEST_METHOD"] == "POST") { try { $pdo = db(); // Ensure doctors table is up-to-date $pdo->exec("CREATE TABLE IF NOT EXISTS doctors ( id INT AUTO_INCREMENT PRIMARY KEY, hospital_id INT NULL, full_name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, specialty VARCHAR(255), qualifications TEXT, specialities TEXT, contact_phone VARCHAR(255), license_number VARCHAR(255), cv_path VARCHAR(255), license_upload_path VARCHAR(255), consultation_fee DECIMAL(10, 2), availability TEXT, status VARCHAR(50) DEFAULT 'pending', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (hospital_id) REFERENCES hospitals(id) ON DELETE SET NULL )"); // Add hospital_id column if it doesn't exist (for backward compatibility) $pdo->exec("ALTER TABLE `doctors` ADD COLUMN IF NOT EXISTS `hospital_id` INT NULL AFTER `id`, ADD INDEX (`hospital_id`);"); // File upload handling $cv_path = null; if (isset($_FILES['cv']) && $_FILES['cv']['error'] == UPLOAD_ERR_OK) { $upload_dir = 'uploads/doctors/'; if (!is_dir($upload_dir)) mkdir($upload_dir, 0775, true); $file_name = uniqid() . '-cv-' . basename($_FILES['cv']['name']); $cv_path = $upload_dir . $file_name; if (!move_uploaded_file($_FILES['cv']['tmp_name'], $cv_path)) { throw new Exception("Failed to upload CV file."); } } $license_upload_path = null; if (isset($_FILES['licenseUpload']) && $_FILES['licenseUpload']['error'] == UPLOAD_ERR_OK) { $upload_dir = 'uploads/doctors/'; if (!is_dir($upload_dir)) mkdir($upload_dir, 0775, true); $file_name = uniqid() . '-license-' . basename($_FILES['licenseUpload']['name']); $license_upload_path = $upload_dir . $file_name; if (!move_uploaded_file($_FILES['licenseUpload']['tmp_name'], $license_upload_path)) { throw new Exception("Failed to upload license file."); } } // Hash password $password_hash = password_hash($_POST['password'], PASSWORD_DEFAULT); $hospital_id = !empty($_POST['hospital_id']) ? $_POST['hospital_id'] : null; // Insert data $stmt = $pdo->prepare( "INSERT INTO doctors (hospital_id, full_name, email, password, specialty, license_number, cv_path, license_upload_path, consultation_fee, availability, qualifications, specialities, contact_phone) VALUES (:hospital_id, :full_name, :email, :password, :specialty, :license_number, :cv_path, :license_upload_path, :consultation_fee, :availability, :qualifications, :specialities, :contact_phone)" ); $stmt->bindParam(':hospital_id', $hospital_id, PDO::PARAM_INT); $stmt->bindParam(':full_name', $_POST['fullName']); $stmt->bindParam(':email', $_POST['email']); $stmt->bindParam(':password', $password_hash); $stmt->bindParam(':specialty', $_POST['specialty']); $stmt->bindParam(':license_number', $_POST['licenseNumber']); $stmt->bindParam(':cv_path', $cv_path); $stmt->bindParam(':license_upload_path', $license_upload_path); $stmt->bindParam(':consultation_fee', $_POST['consultationFee']); $stmt->bindParam(':availability', $_POST['availability']); $stmt->bindParam(':qualifications', $_POST['qualifications']); $stmt->bindParam(':specialities', $_POST['specialities']); $stmt->bindParam(':contact_phone', $_POST['contact_phone']); $stmt->execute(); $success_message = "Registration successful! Your profile will be reviewed shortly."; } 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(); } } ?>
Join our network of trusted medical professionals.