"`$c`", $nutrients)); $placeholders = implode(', ', array_fill(0, count($nutrients) + 3, '?')); $values = [$userId, $name, $chemical]; foreach ($nutrients as $col) { $val = trim((string) ($_POST[$col] ?? '0')); $values[] = is_numeric($val) ? $val : '0'; } try { $stmt = $pdo->prepare("INSERT INTO fertiliser_specifications ($colList) VALUES ($placeholders)"); $stmt->execute($values); $_SESSION['flash_success'] = 'Product "' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '" added successfully.'; } catch (\PDOException $e) { $_SESSION['flash_error'] = 'Failed to add product. Please try again.'; } header('Location: /dashboard/client-settings/product-list.php'); exit;