prepare("DELETE FROM colors WHERE id = ?"); $stmt_del->execute([$delete_id]); $success = 'Color swatch removed successfully!'; echo ""; } catch (Exception $e) { $error = 'Failed to delete color: ' . $e->getMessage(); } } // Handle Form Submission (Add or Edit) if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = isset($_POST['name']) ? trim($_POST['name']) : ''; $hex = isset($_POST['hex']) ? trim($_POST['hex']) : ''; $border = isset($_POST['border']) ? trim($_POST['border']) : '#FFFFFF'; $action = isset($_POST['action']) ? $_POST['action'] : 'add'; $color_id = isset($_POST['color_id']) ? intval($_POST['color_id']) : 0; if (empty($name) || empty($hex)) { $error = 'Both Color Name and HEX Code are required.'; } else { // Simple hex format check if (!preg_match('/^#[a-fA-F0-9]{6}$/', $hex)) { $error = 'Invalid HEX code format. Must be like #FFFFFF.'; } else { try { if ($action === 'edit' && $color_id > 0) { // Update existing color $stmt_update = $pdo->prepare("UPDATE colors SET name = ?, hex = ?, border = ? WHERE id = ?"); $stmt_update->execute([$name, $hex, $border, $color_id]); $success = 'Color swatch updated successfully!'; echo ""; } else { // Add new color // Check duplicate name $stmt_check = $pdo->prepare("SELECT COUNT(*) FROM colors WHERE name = ?"); $stmt_check->execute([$name]); if ($stmt_check->fetchColumn() > 0) { $error = 'A color swatch with this name already exists.'; } else { $stmt_insert = $pdo->prepare("INSERT INTO colors (name, hex, border) VALUES (?, ?, ?)"); $stmt_insert->execute([$name, $hex, $border]); $success = 'New color swatch introduced successfully!'; echo ""; } } } catch (Exception $e) { $error = 'Database transaction failed: ' . $e->getMessage(); } } } } // Check if we are in Edit Mode if (isset($_GET['edit'])) { $edit_id = intval($_GET['edit']); try { $stmt_edit = $pdo->prepare("SELECT * FROM colors WHERE id = ?"); $stmt_edit->execute([$edit_id]); $editing_color = $stmt_edit->fetch(); } catch (Exception $e) { $error = 'Failed to load color for editing.'; } } // Fetch all colors $colors = []; try { $colors = $pdo->query("SELECT * FROM colors ORDER BY name ASC")->fetchAll(); } catch (Exception $e) { $error = 'Failed to retrieve catalog colors: ' . $e->getMessage(); } ?>

Couture Colors Management

Design, add, and refine the luxury color palettes available for your masterworks catalog.

Active Color Swatches

No color palettes have been defined.
Swatch Color Name HEX Code Border Color Actions

Refine Swatch Details Add New Color Swatch

Choose a premium fashion name.
Enter hex code or use the color picker swatch on the left.
Required to guarantee swatch visibility on black backgrounds (e.g. white/gray swatches).
Cancel