prepare("SELECT * FROM users WHERE username = ? OR email = ?"); $stmt->execute([$username, $email]); if ($stmt->fetch()) { header('Location: user_management.php?error=user_exists'); exit; } $hashed_password = password_hash($password, PASSWORD_DEFAULT); $division_id = $_POST['division_id'] ?? null; $department_id = $_POST['department_id'] ?? null; $stmt = $pdo->prepare("INSERT INTO users (username, email, password, role_id, division_id, department_id) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$username, $email, $hashed_password, $role_id, $division_id, $department_id]); header('Location: user_management.php?success=user_created'); exit; } catch (PDOException $e) { header('Location: user_management.php?error=db_error'); exit; } }