connect_error) { die("Datenbankfehler"); } /* ======================= 3) Kategorien laden ======================= */ $categories = []; $result = $conn->query(" SELECT categoryID, name FROM categories ORDER BY name "); while ($row = $result->fetch_assoc()) { $categories[] = $row; } /* ======================= 4) Attribute zur Kategorie ======================= */ $attributes = []; if ($categoryID > 0) { $stmt = $conn->prepare(" SELECT a.attributeID, a.name, a.unit, a.dataType FROM categoryAttributes ca JOIN attributes a ON a.attributeID = ca.attributeID WHERE ca.categoryID = ? ORDER BY a.name "); $stmt->bind_param("i", $categoryID); $stmt->execute(); $res = $stmt->get_result(); while ($row = $res->fetch_assoc()) { $attributes[] = $row; } } /* ======================= 5) Produkt speichern ======================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['saveProduct'])) { $model = trim($_POST['model']); $description = $_POST['description'] ?? null; $categoryID = (int)$_POST['categoryID']; // --- Produkt anlegen --- $stmt = $conn->prepare(" INSERT INTO products (categoryID, model, description) VALUES (?, ?, ?) "); $stmt->bind_param("iss", $categoryID, $model, $description); $stmt->execute(); $productID = $stmt->insert_id; // --- Attribute speichern --- if (!empty($_POST['attributes'])) { $stmtAttr = $conn->prepare(" INSERT INTO productAttributes (productID, attributeID, valueString, valueNumber, valueBool) VALUES (?, ?, ?, ?, ?) "); foreach ($_POST['attributes'] as $attributeID => $value) { if ($value === '' || $value === null) { continue; } $valueString = null; $valueNumber = null; $valueBool = null; if (is_numeric($value)) { $valueNumber = $value; } elseif ($value === '0' || $value === '1') { $valueBool = (int)$value; } else { $valueString = trim($value); } $stmtAttr->bind_param( "iisdi", $productID, $attributeID, $valueString, $valueNumber, $valueBool ); $stmtAttr->execute(); } } header("Location: product_add.php?categoryID=" . $categoryID); exit; } include 'header.php'; ?> Kategorie waehlen Kategorie Kategorie waehlen > = htmlspecialchars($cat['name']) ?> 0): ?> Produkt hinzufuegen Modell Beschreibung Attribute = htmlspecialchars($attr['name']) ?> (= htmlspecialchars($attr['unit']) ?>) Produkt speichern close(); include 'footer.php'; ?>