beginTransaction(); try { $stmt = $db->prepare("INSERT INTO learners (full_name, grade, student_id, parent_email, school_id) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE full_name = VALUES(full_name), grade = VALUES(grade), parent_email = VALUES(parent_email)"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if (count($data) >= 3) { $full_name = trim($data[0]); $grade = trim($data[1]); $student_id = trim($data[2]); $parent_email = isset($data[3]) ? trim($data[3]) : null; if (!empty($full_name) && !empty($grade) && !empty($student_id)) { $stmt->execute([$full_name, $grade, $student_id, $parent_email, $school_id]); $success_count++; } else { $fail_count++; } } else { $fail_count++; } } $db->commit(); $message = "Successfully imported $success_count learners. (Skipped/Failed: $fail_count)"; } catch (Exception $e) { $db->rollBack(); $error = "Database error: " . $e->getMessage(); } fclose($handle); } else { $error = "Could not open the uploaded file."; } } } include 'includes/header.php'; ?>

Bulk Upload Learners

Upload a CSV file to add multiple learners at once.

Format: Full Name, Grade, Student ID, Parent Email (optional).
CSV Template Guide

Your CSV file should look like this:

Full Name,Grade,Student ID,Parent Email
John Doe,10,SOW-101,parent@example.com
Jane Smith,11,SOW-102,jane_parent@gmail.com
Bob Brown,10,SOW-103,
  • The first line is treated as a header and skipped.
  • Existing Student IDs will be updated.
  • Parent Email is used for automated performance notifications.