Database Setup Failed

Could not create database tables. Please check:

Update config/database.php with correct credentials and refresh this page.

'); } // Check if admin user already exists try { $existingAdmin = fetchRow("SELECT id FROM users WHERE role = 'admin' LIMIT 1"); if ($existingAdmin) { die('

Setup Already Complete

An admin user already exists. Please delete this setup.php file for security.

Go to Login
'); } } catch (Exception $e) { // Tables might not exist yet, continue with setup } /** * Initialize database tables if they don't exist */ function initializeDatabaseTables() { global $pdo; try { // Read and execute the database schema $sqlFile = __DIR__ . '/sql/database.sql'; if (!file_exists($sqlFile)) { error_log("Database schema file not found: " . $sqlFile); return false; } $sql = file_get_contents($sqlFile); if ($sql === false) { error_log("Could not read database schema file"); return false; } // Split SQL into individual statements $statements = array_filter(array_map('trim', explode(';', $sql))); foreach ($statements as $statement) { if (!empty($statement) && !preg_match('/^\s*--/', $statement)) { try { $pdo->exec($statement); } catch (PDOException $e) { // Ignore "table already exists" errors if (strpos($e->getMessage(), 'already exists') === false) { error_log("Database setup error: " . $e->getMessage() . " | Statement: " . $statement); } } } } return true; } catch (Exception $e) { error_log("Database initialization failed: " . $e->getMessage()); return false; } } $error = ''; $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = sanitizeInput($_POST['username'] ?? ''); $email = sanitizeInput($_POST['email'] ?? ''); $fullName = sanitizeInput($_POST['full_name'] ?? ''); $phone = sanitizeInput($_POST['phone'] ?? ''); $password = $_POST['password'] ?? ''; $confirmPassword = $_POST['confirm_password'] ?? ''; try { // Validation if (empty($username) || empty($email) || empty($fullName) || empty($password)) { throw new Exception('All fields are required.'); } if (!isValidEmail($email)) { throw new Exception('Please enter a valid email address.'); } if (strlen($password) < 8) { throw new Exception('Password must be at least 8 characters long.'); } if ($password !== $confirmPassword) { throw new Exception('Passwords do not match.'); } if ($phone && !isValidPhone($phone)) { throw new Exception('Please enter a valid phone number.'); } // Check if username or email already exists $existingUser = fetchRow( "SELECT id FROM users WHERE username = ? OR email = ?", [$username, $email] ); if ($existingUser) { throw new Exception('Username or email already exists.'); } // Create admin user $userData = [ 'username' => $username, 'email' => $email, 'password' => hashPassword($password), 'full_name' => $fullName, 'phone' => $phone, 'role' => 'admin', 'status' => 'active', 'created_at' => date('Y-m-d H:i:s') ]; $userId = insertData('users', $userData); if ($userId) { $success = 'Admin user created successfully! Please delete this setup file and login with your credentials.'; // Log the setup activity logSystemActivity('System Setup', 'Admin user created: ' . $username, $userId); } else { throw new Exception('Failed to create admin user.'); } } catch (Exception $e) { $error = $e->getMessage(); } } ?> Setup - Kayal Aqua

Welcome to Kayal Aqua

Fish Business Management System

Important: Please delete the setup.php file from your server for security reasons.
First Time Setup: Create your admin account to get started with Kayal Aqua.
Password Requirements:
  • At least 8 characters long
  • Mix of letters, numbers, and special characters recommended
  • Avoid common passwords
Security Note: This setup file will create your first admin user. After setup is complete, please delete this file (setup.php) from your server.