beginTransaction(); try { $stmt = db()->prepare("INSERT INTO clients (tenant_id, name, email, phone, address, city, province_state, postal_code, country) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); while (($row = fgetcsv($handle)) !== false) { $rowCount++; $data = []; foreach ($expected as $col) { $data[$col] = isset($columnMap[$col]) && isset($row[$columnMap[$col]]) ? trim($row[$columnMap[$col]]) : ''; } if (empty($data['name'])) { $skippedCount++; $results[] = "Row $rowCount: Skipped (Missing Name)"; continue; } // Simple validation: email if (!empty($data['email']) && !filter_var($data['email'], FILTER_VALIDATE_EMAIL)) { $results[] = "Row $rowCount: Warning (Invalid Email: " . htmlspecialchars($data['email']) . ")"; } $stmt->execute([ 1, // Hardcoded tenant_id for now as per app convention $data['name'], $data['email'], $data['phone'], $data['address'], $data['city'], $data['province_state'], $data['postal_code'], $data['country'] ]); $importCount++; } db()->commit(); $message = "Import completed successfully. $importCount clients imported, $skippedCount skipped."; } catch (Exception $e) { db()->rollBack(); $error = 'Database error: ' . $e->getMessage(); } } fclose($handle); } } include 'includes/header.php'; ?>

Import Clients

Download Template
Max file size: 2MB. Only .csv files are allowed.
Import Instructions
  1. Download the CSV template using the button above.
  2. Fill in your client data, ensuring the name field is not empty.
  3. Save the file as a CSV (Comma Separated Values).
  4. Upload the file using the form on the left.
  5. Review any warnings or errors that appear after processing.
Existing clients with the same name will be added as new entries.
Import Logs