Skip to content

Data Import Tool Documentation

Menu Location: Tools > Data Import

Access Level: Administrator

Last Updated: 2026-03-01


Overview

The Data Import Tool allows administrators to bulk import data from CSV or XLSX files into database tables. It provides a three-step wizard for file upload, column mapping, and data insertion with validation and error reporting.

Primary Functions:

  • Upload CSV or XLSX files for data import
  • Map file columns to database fields
  • Preview data before importing
  • Execute bulk inserts with error handling
  • Review import results and error details

Page Layout

Step 1: File Upload

  • Info Callout: Instructions for file selection
  • File Upload Field: Accepts .csv or .xlsx files
  • Upload Button: Proceeds to column mapping
  • Cancel Link: Returns to admin area

Step 2: Column Mapping

  • Info Callout: Explanation of mapping process
  • File Summary: Shows filename and row count
  • Mapping Table: Three columns (File Column, Sample Data, Database Field)
  • Continue Button: Proceeds to preview
  • Start Over Link: Returns to file upload

Step 3: Preview & Confirm

  • Warning Callout: Emphasizes action is irreversible
  • Import Summary: File details, row count, column count
  • Preview Table: First 10 rows of mapped data
  • Confirm Import Button: Executes the import
  • Navigation Links: Back to mapping or start over

Step 4: Results

  • Success/Error Callouts: Import completion status
  • Statistics: Successful and failed row counts
  • Error Details: Specific error messages for failed rows
  • Action Links: Import another file or return to admin

Import Workflow

Step 1: File Upload

Process:

  1. Navigate to tool from table admin page
  2. Click "Choose File" button
  3. Select CSV or XLSX file
  4. Click "Upload and Continue"
  5. File is parsed and stored in session
  6. Headers extracted, data rows counted
  7. Redirects to Step 2

Supported Formats:

  • CSV: Comma-delimited text files
  • XLSX: Excel 2007+ spreadsheet files

File Requirements:

  • First row must contain column headers
  • Empty rows are automatically skipped
  • Maximum file size limited by PHP configuration
  • UTF-8 encoding recommended for special characters

Validation:

  • File extension must be .csv or .xlsx
  • File must not be empty
  • At least one data row required (beyond header)
  • Parseable format required

Step 2: Column Mapping

Process:

  1. Review file columns and sample data
  2. For each file column, select matching database field
  3. Leave unmapped if column should be skipped
  4. Auto-matching attempts to pair columns by name
  5. Click "Continue to Preview"
  6. Mapping stored in session
  7. Redirects to Step 3

Mapping Table:

  • File Column: Column name from uploaded file
  • Sample Data: First row's value for this column (truncated to 100 chars)
  • Map to Database Column: Dropdown showing available database fields

Auto-Matching Logic:

  • Case-insensitive name comparison
  • Handles spaces converted to underscores
  • Example: "First Name" auto-maps to "first_name"
  • Manual override always available

Excluded Columns:

  • Auto-increment fields (typically "id")
  • These cannot be manually set via import
  • Shown in dropdown but skipped in interface

Skip Columns:

  • Select "-- Skip this column --" to ignore
  • Useful for file columns not needed in database
  • Reduces clutter and potential errors

Step 3: Preview & Confirm

Process:

  1. Review import summary statistics
  2. Examine first 10 rows of mapped data
  3. Verify column mapping appears correct
  4. Click "Confirm Import" if ready
  5. Or click "Back to Mapping" to adjust
  6. Confirmation prompt warns action is irreversible
  7. Clicking OK executes import
  8. Redirects to Step 4 with results

Preview Table:

  • Shows database field names as column headers
  • Includes source file column name as subtitle
  • First 10 rows displayed
  • "...and N more rows" note if file larger

Safety Features:

  • Explicit "cannot be undone" warning
  • JavaScript confirmation dialog
  • Preview before execution
  • Back button to adjust mapping

Step 4: Results & Error Reporting

Process:

  1. System attempts INSERT for each row
  2. Successful rows counted and reported
  3. Failed rows counted with error messages
  4. Results stored in session
  5. Success/error callouts displayed
  6. Error details shown in scrollable well
  7. Links provided for next actions

Success Information:

  • Green callout with checkmark icon
  • "Successfully imported N rows" message
  • Count of successful insertions

Error Information:

  • Red callout with X icon
  • "N rows failed to import" message
  • Detailed error list with row numbers

Error Detail Format:

Row 5: Duplicate entry for key 'email'
Row 12: Cannot insert NULL into required field 'first_name'
Row 23: Invalid date format for field 'created_date'

Next Actions:

  • Import Another File: Returns to Step 1 for same table
  • Back to Admin: Returns to table admin page

Column Mapping

Mapping Options

Required vs Optional Fields:

  • Database determines which fields required
  • Import will fail if required field unmapped AND has no default
  • Optional fields can be left unmapped
  • NULL/empty values used for unmapped optional fields

Data Type Considerations:

  • Tool doesn't validate data types during mapping
  • Validation occurs during INSERT
  • Type mismatches cause row to fail with error message
  • Example: Text into integer field fails

Best Practices:

  1. Map all required database fields
  2. Verify data types align (dates, numbers, text)
  3. Use sample data to confirm correct mapping
  4. Map primary key only if intentionally setting IDs
  5. Skip unnecessary file columns

Auto-Increment ID Handling

Default Behavior:

  • Auto-increment fields (usually "id") automatically excluded
  • Cannot be mapped in interface
  • Database assigns sequential IDs automatically

If You Need to Set IDs:

  • Contact system administrator
  • May require manual import via SQL
  • Risk of duplicate key errors if IDs already exist

Common Mapping Scenarios

Scenario 1: Perfect Column Name Match

File Column: first_name
Database Field: first_name
Auto-Match: Yes
Action: Verify and continue

Scenario 2: Similar Names

File Column: First Name
Database Field: first_name
Auto-Match: Yes (space to underscore)
Action: Verify and continue

Scenario 3: Different Names

File Column: Customer Name
Database Field: full_name
Auto-Match: No
Action: Manually select "full_name"

Scenario 4: Extra File Columns

File Column: Internal Notes
Database Field: (none needed)
Auto-Match: No
Action: Select "-- Skip this column --"

Scenario 5: Split Columns

File Columns: First Name, Last Name
Database Field: full_name
Action: Cannot combine - may need pre-processing


Common Use Cases

Use Case 1: Import Customer List from Excel

Goal: Bulk import new customer records from spreadsheet

Steps:

  1. Prepare Excel file with customer data
  2. Ensure first row has column headers
  3. Save as .xlsx or export as .csv
  4. Navigate to admin-import.php?table=custy
  5. Upload file
  6. Map columns (email, first_name, last_name, phone, etc.)
  7. Preview first 10 records
  8. Confirm and import
  9. Review results for errors

Example: Import 500 customer records from marketing list. 495 succeed, 5 fail due to duplicate emails. Review errors, update source data, re-import 5 records.

Tips:

  • Validate email addresses before import
  • Check for duplicates in source file first
  • Include phone number formatting
  • Set account_type and other defaults in source

Use Case 2: Bulk Product Update

Goal: Update multiple product records from CSV

Steps:

  1. Export current products to CSV
  2. Edit prices, descriptions, availability in Excel
  3. Save as CSV
  4. Navigate to admin-import.php?table=menu
  5. Upload edited CSV
  6. Map id column (to update existing records)
  7. Map fields to update
  8. Preview changes
  9. Confirm import

Warning:

  • Including ID column updates existing records
  • Without ID, creates new duplicate records
  • Test with small batch first

Use Case 3: Import Historical Order Data

Goal: Migrate order records from old system

Steps:

  1. Export orders from legacy system
  2. Transform data to match cust_order schema
  3. Ensure customer IDs already exist
  4. Format dates as YYYY-MM-DD or timestamps
  5. Navigate to admin-import.php?table=cust_order
  6. Upload transformed CSV
  7. Map all required fields carefully
  8. Preview extensively (check dates, amounts)
  9. Confirm import
  10. Verify order totals and customer links

Critical Fields:

  • customer (must match existing custy.id)
  • deliver_on (use Unix timestamp)
  • payment_total (numeric, no currency symbols)
  • status (use valid status code)

Tips:

  • Import in small batches (100-500 rows)
  • Verify foreign keys exist first
  • Check timestamp format matches system
  • Test with 10 records before full import

Use Case 4: Update Email Addresses

Goal: Correct email addresses for bounced emails

Steps:

  1. Export bounce report with customer IDs and new emails
  2. Create CSV with: id, email columns
  3. Navigate to admin-import.php?table=custy
  4. Upload CSV
  5. Map id to id, email to email
  6. Preview to verify ID matches
  7. Confirm import
  8. Check updated customer records

Warning:

  • ID column causes UPDATE not INSERT
  • Verify IDs are correct before import
  • Email validation only happens at database level

Use Case 5: Bulk Add Promotion Tags

Goal: Tag multiple customers for targeted campaign

Steps:

  1. Identify customer IDs for campaign
  2. Create CSV with customer_id, tag_id, created_date
  3. Navigate to admin-import.php?table=promotions_tagging
  4. Upload CSV
  5. Map columns appropriately
  6. Preview to verify customer/tag associations
  7. Confirm import
  8. Verify tags in customer records

Tips:

  • Ensure tag_id exists in PromotionsTags table
  • Use current timestamp for created_date
  • Check for existing tags to avoid duplicates

Troubleshooting

File Upload Fails

Symptoms: Error message after clicking "Upload and Continue"

Common Errors:

  • "Please upload a CSV or XLSX file": Wrong file extension
  • "The uploaded file is empty": File has no data rows
  • "No data found in file": Only header row, no data

Solutions:

  1. Verify file extension is .csv or .xlsx
  2. Open file to confirm data rows exist
  3. Check file isn't corrupted
  4. Ensure at least one row beyond header
  5. Try exporting from source system again

Column Mapping Doesn't Save

Symptoms: Clicking "Continue to Preview" returns to mapping or shows error

Check:

  1. Verify at least one column is mapped
  2. Check if required fields are unmapped
  3. Ensure mapping selections were saved

Solutions:

  1. Map at least one column before continuing
  2. Check that dropdown selections took effect
  3. Reload page if browser cached old state

All Rows Fail During Import

Symptoms: Results page shows 0 successful, all rows failed

Common Causes:

  • Required field unmapped
  • Data type mismatches throughout file
  • Foreign key violations (referenced ID doesn't exist)
  • Unique constraint violations (duplicate values)

Solutions:

  1. Review error messages for specific issues
  2. Check database schema for required fields
  3. Validate data types in source file
  4. Verify foreign key IDs exist before import
  5. Remove duplicate values from source

Some Rows Fail, Others Succeed

Symptoms: Partial import with error details

Common Issues:

  • Inconsistent data quality in source
  • Some rows violate constraints
  • Duplicate values in specific rows
  • Invalid format in some cells

Solutions:

  1. Review error details for row numbers
  2. Check those specific rows in source file
  3. Fix data issues
  4. Re-import failed rows only
  5. Or fix all issues and re-import entire file

Import Succeeds But Data Looks Wrong

Symptoms: No errors but imported data doesn't match source

Check:

  1. Verify column mapping was correct
  2. Check if you mapped to wrong database fields
  3. Confirm data transformations weren't needed
  4. Review preview more carefully next time

Solutions:

  1. May need to delete imported records
  2. Fix mapping or source data
  3. Re-import correctly
  4. Use sample data preview more carefully

  • Table Admin (admin-edit.php?table=...) - View and manage imported records
  • Database Schema (/kiv/database_schema/) - Review table structure before import
  • Export Tool (export.php) - Export data before modification imports

Typical Workflow:

  1. Table Admin → Notice bulk data needed → Import Tool → Upload and map
  2. External system → Export data → Import Tool → Verify in Table Admin
  3. Import Tool → Review errors → Fix source data → Re-import

Permissions & Access

Required Access Level: Administrator

Security Note:

  • Direct database insert access
  • Can corrupt data if used incorrectly
  • Should be restricted to trained staff
  • Always test with small sample first

Best Practices

Before Import

  1. Review database schema to understand required fields
  2. Validate source data for completeness and accuracy
  3. Check for duplicates in source file
  4. Test with 10-20 rows before full import
  5. Backup database if updating existing records

During Import

  1. Review sample data carefully during mapping
  2. Double-check column mappings
  3. Read preview table thoroughly
  4. Understand which rows are being affected
  5. Click through prompts deliberately, not quickly

After Import

  1. Verify row counts match expectations
  2. Review error details if any failures
  3. Spot-check imported records in admin
  4. Test functionality affected by import
  5. Document what was imported and when

Things to Avoid

  • ❌ Don't import without reviewing schema first
  • ❌ Don't map columns blindly - verify each one
  • ❌ Don't skip the preview step
  • ❌ Don't import into production without testing first
  • ❌ Don't import IDs unless intentionally updating records

Quick Reference Card

Task Action/Location
Start import Navigate to admin-import.php?table=[tablename]
Upload file Choose file, click Upload and Continue
Skip file column Select "-- Skip this column --"
Auto-map columns Tool attempts automatically, verify each
Preview before import Review Step 3 table carefully
Execute import Click Confirm Import, confirm dialog
Review errors Check Step 4 error details
Re-import failures Fix source data, start over with failed rows
Import more data Click "Import Another File"
Return to admin Click "Back to Admin"

FAQs

Can I update existing records or only create new ones?

By default, the tool creates new records (INSERT). If you map the ID column, it MAY update existing records depending on database configuration, but this isn't guaranteed and can cause errors. For updates, use the table admin interface or contact system administrator.

What happens if I upload a file with 10,000 rows?

The import will attempt all 10,000 inserts. This may take a while and could timeout on very large files. For large imports, break into batches of 500-1000 rows.

Can I combine multiple file columns into one database field?

No, the current tool doesn't support data transformation or combining. You must pre-process your file to have one file column per database field.

What if my import fails halfway through?

Failed rows are logged but successfully inserted rows remain in database. You cannot automatically rollback. You'll need to manually remove successful rows or re-import all data after fixing issues.

Can I import dates and times?

Yes, but ensure your date format matches what the database expects. Unix timestamps work best. YYYY-MM-DD format typically works for date fields. Test with a small sample to verify.


Change Log

2026-03-01

  • Initial documentation created
  • All sections completed based on admin-import.php code review
  • Documented three-step wizard flow
  • Added column mapping details
  • Included error handling and troubleshooting
  • Noted CSV and XLSX support via PhpSpreadsheet

End of Documentation

For additional help, contact your system administrator or Kiva Logic support.