diff --git a/productAdder.php b/productAdder.php index 5f8606f..ac99854 100644 --- a/productAdder.php +++ b/productAdder.php @@ -35,6 +35,19 @@ while ($row = $result->fetch_assoc()) { $categories[] = $row; } +/* ======================= + 3b) Marken laden + ======================= */ +$brands = []; +$result = $conn->query(" + SELECT brandID, name + FROM brands + ORDER BY name +"); +while ($row = $result->fetch_assoc()) { + $brands[] = $row; +} + /* ======================= 4) Attribute zur Kategorie ======================= */ @@ -58,63 +71,69 @@ if ($categoryID > 0) { /* ======================= 5) Produkt speichern ======================= */ +$saveError = null; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['saveProduct'])) { $model = trim($_POST['model']); $description = $_POST['description'] ?? null; $categoryID = (int)$_POST['categoryID']; + $brandID = (int)($_POST['brandID'] ?? 0); - // --- 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 (?, ?, ?, ?, ?) + if ($brandID <= 0) { + $saveError = 'Bitte eine Marke auswählen.'; + } else { + // --- Produkt anlegen --- + $stmt = $conn->prepare(" + INSERT INTO products (categoryID, brandID, model, description) + VALUES (?, ?, ?, ?) "); + $stmt->bind_param("iiss", $categoryID, $brandID, $model, $description); + $stmt->execute(); - foreach ($_POST['attributes'] as $attributeID => $value) { + $productID = $stmt->insert_id; - if ($value === '' || $value === null) { - continue; + // --- 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(); } - - $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; + header("Location: productAdder.php?categoryID=" . $categoryID); + exit; + } } include 'header.php'; @@ -129,13 +148,13 @@ include 'header.php';
-

Kategorie waehlen

+

Kategorie wählen

+ +

+ + + + +