❌ PROBLEM FOUND: Missing first_name or surname columns!
‘;
echo ‘
‘;
echo ‘‘;
echo ‘
‘;
} else {
echo ‘
✅ Database structure is correct (v2.1)
‘;
}
// Check for email unique constraint
$indexes = $wpdb->get_results(“SHOW INDEXES FROM $clients_table WHERE Column_name = ’email'”);
$has_unique_email = false;
foreach ($indexes as $index) {
if ($index->Non_unique == 0) {
$has_unique_email = true;
break;
}
}
if ($has_unique_email) {
echo ‘
✅ Email has UNIQUE constraint
‘;
} else {
echo ‘
⚠️ Email does NOT have UNIQUE constraint
‘;
}
// Count records
echo “
Data Count
“;
$client_count = $wpdb->get_var(“SELECT COUNT(*) FROM $clients_table”);
$session_count = $wpdb->get_var(“SELECT COUNT(*) FROM $sessions_table”);
echo “
“;
echo “
Table
Record Count
“;
echo “
Clients
$client_count
“;
echo “
Sessions
$session_count
“;
echo “
“;
if ($client_count == 0) {
echo ‘
⚠️ No clients found! They may have been lost during migration.
‘;
}
// Show sample data
if ($client_count > 0) {
echo “
Sample Client Data (First 5)
“;
$sample_clients = $wpdb->get_results(“SELECT * FROM $clients_table LIMIT 5”);
if (!empty($sample_clients)) {
echo “
“;
echo “
“;
foreach ($sample_clients[0] as $key => $value) {
echo “
” . esc_html($key) . “
“;
}
echo “
“;
foreach ($sample_clients as $client) {
echo “
“;
foreach ($client as $value) {
echo “
” . esc_html($value) . “
“;
}
echo “
“;
}
echo “
“;
}
}
}
?>
🔧 Step 2: Available Fixes
📝 Manual Migration SQL
If the automatic migration fails, run this SQL in phpMyAdmin:
⚠️ Important Notes
Always backup your database before running fixes!
If you had clients before the update, they should still be in the database
The migration script converts old “name” field to “first_name” and “surname”
DELETE this file after use for security!
Starting migration…
‘;
// Check if old structure exists
$columns = $wpdb->get_results(“DESCRIBE $clients_table”);
$column_names = array_column($columns, ‘Field’);
$has_old_name = in_array(‘name’, $column_names);
if (!$has_old_name) {
echo ‘
❌ Old “name” column not found. Nothing to migrate.
‘;
exit;
}
// Step 1: Add new columns
$wpdb->query(“ALTER TABLE `{$clients_table}` ADD COLUMN IF NOT EXISTS `first_name` VARCHAR(100) NOT NULL DEFAULT ” AFTER `id`”);
$wpdb->query(“ALTER TABLE `{$clients_table}` ADD COLUMN IF NOT EXISTS `surname` VARCHAR(100) NOT NULL DEFAULT ” AFTER `first_name`”);
echo ‘
✅ Added first_name and surname columns
‘;
// Step 2: Migrate data
$result = $wpdb->query(”
UPDATE `{$clients_table}`
SET
`first_name` = SUBSTRING_INDEX(`name`, ‘ ‘, 1),
`surname` = SUBSTRING_INDEX(`name`, ‘ ‘, -1)
WHERE `name` IS NOT NULL AND `name` != ”
“);
echo ‘
✅ Migrated ‘ . $result . ‘ client names
‘;
// Step 3: Handle single-word names
$wpdb->query(“UPDATE `{$clients_table}` SET `surname` = `first_name` WHERE `surname` = ” OR `surname` IS NULL”);
echo ‘
✅ Fixed single-word names
‘;
// Step 4: Drop old column
$wpdb->query(“ALTER TABLE `{$clients_table}` DROP COLUMN `name`”);
echo ‘