fix: Verhindere Duplicate entry Fehler für Hersteller und Kategorien bei Artikelerstellung/-bearbeitung
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 10s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 10s
This commit is contained in:
@@ -152,21 +152,41 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (isset($_POST['manufacturer_id']) && $_POST['manufacturer_id'] === 'new') {
|
||||
$new_manufacturer_name = trim($_POST['new_manufacturer_name']);
|
||||
if (!empty($new_manufacturer_name)) {
|
||||
$stmt_man = $conn->prepare("INSERT INTO manufacturers (name, user_id) VALUES (?, ?)");
|
||||
$stmt_man->bind_param("si", $new_manufacturer_name, $current_user_id);
|
||||
if ($stmt_man->execute()) { $manufacturer_id = $conn->insert_id; }
|
||||
$stmt_man->close();
|
||||
}
|
||||
$stmt_check = $conn->prepare("SELECT id FROM manufacturers WHERE name = ? AND user_id IN ($placeholders)");
|
||||
$check_params = array_merge([$new_manufacturer_name], $household_member_ids);
|
||||
$stmt_check->bind_param("s" . $types, ...$check_params);
|
||||
$stmt_check->execute();
|
||||
$res_check = $stmt_check->get_result();
|
||||
if ($res_check->num_rows > 0) {
|
||||
$manufacturer_id = $res_check->fetch_assoc()['id'];
|
||||
} else {
|
||||
$stmt_man = $conn->prepare("INSERT INTO manufacturers (name, user_id) VALUES (?, ?)");
|
||||
$stmt_man->bind_param("si", $new_manufacturer_name, $current_user_id);
|
||||
if ($stmt_man->execute()) { $manufacturer_id = $conn->insert_id; }
|
||||
$stmt_man->close();
|
||||
}
|
||||
$stmt_check->close();
|
||||
} else { $manufacturer_id = NULL; }
|
||||
} else { $manufacturer_id = !empty($_POST['manufacturer_id']) ? intval($_POST['manufacturer_id']) : NULL; }
|
||||
|
||||
if (isset($_POST['category_id']) && $_POST['category_id'] === 'new') {
|
||||
$new_category_name = trim($_POST['new_category_name']);
|
||||
if (!empty($new_category_name)) {
|
||||
$stmt_cat = $conn->prepare("INSERT INTO categories (name, user_id) VALUES (?, ?)");
|
||||
$stmt_cat->bind_param("si", $new_category_name, $current_user_id);
|
||||
if($stmt_cat->execute()){ $category_id = $conn->insert_id; }
|
||||
$stmt_cat->close();
|
||||
}
|
||||
$stmt_check = $conn->prepare("SELECT id FROM categories WHERE name = ? AND user_id IN ($placeholders)");
|
||||
$check_params = array_merge([$new_category_name], $household_member_ids);
|
||||
$stmt_check->bind_param("s" . $types, ...$check_params);
|
||||
$stmt_check->execute();
|
||||
$res_check = $stmt_check->get_result();
|
||||
if ($res_check->num_rows > 0) {
|
||||
$category_id = $res_check->fetch_assoc()['id'];
|
||||
} else {
|
||||
$stmt_cat = $conn->prepare("INSERT INTO categories (name, user_id) VALUES (?, ?)");
|
||||
$stmt_cat->bind_param("si", $new_category_name, $current_user_id);
|
||||
if($stmt_cat->execute()){ $category_id = $conn->insert_id; }
|
||||
$stmt_cat->close();
|
||||
}
|
||||
$stmt_check->close();
|
||||
} else { $category_id = NULL; }
|
||||
} else { $category_id = !empty($_POST['category_id']) ? intval($_POST['category_id']) : NULL; }
|
||||
|
||||
$image_url_for_db = NULL;
|
||||
|
||||
@@ -257,20 +257,40 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) {
|
||||
if (isset($_POST['manufacturer_id']) && $_POST['manufacturer_id'] === 'new') {
|
||||
$new_manufacturer_name = trim($_POST['new_manufacturer_name']);
|
||||
if (!empty($new_manufacturer_name)) {
|
||||
$stmt_man = $conn->prepare("INSERT INTO manufacturers (name, user_id) VALUES (?, ?)");
|
||||
$stmt_man->bind_param("si", $new_manufacturer_name, $current_user_id);
|
||||
if ($stmt_man->execute()) { $manufacturer_id = $conn->insert_id; }
|
||||
$stmt_man->close();
|
||||
$stmt_check = $conn->prepare("SELECT id FROM manufacturers WHERE name = ? AND user_id IN ($placeholders)");
|
||||
$check_params = array_merge([$new_manufacturer_name], $household_member_ids);
|
||||
$stmt_check->bind_param("s" . $types, ...$check_params);
|
||||
$stmt_check->execute();
|
||||
$res_check = $stmt_check->get_result();
|
||||
if ($res_check->num_rows > 0) {
|
||||
$manufacturer_id = $res_check->fetch_assoc()['id'];
|
||||
} else {
|
||||
$stmt_man = $conn->prepare("INSERT INTO manufacturers (name, user_id) VALUES (?, ?)");
|
||||
$stmt_man->bind_param("si", $new_manufacturer_name, $current_user_id);
|
||||
if ($stmt_man->execute()) { $manufacturer_id = $conn->insert_id; }
|
||||
$stmt_man->close();
|
||||
}
|
||||
$stmt_check->close();
|
||||
} else { $manufacturer_id = NULL; }
|
||||
} else { $manufacturer_id = !empty($_POST['manufacturer_id']) ? intval($_POST['manufacturer_id']) : NULL; }
|
||||
|
||||
if (isset($_POST['category_id']) && $_POST['category_id'] === 'new') {
|
||||
$new_category_name = trim($_POST['new_category_name']);
|
||||
if (!empty($new_category_name)) {
|
||||
$stmt_cat = $conn->prepare("INSERT INTO categories (name, user_id) VALUES (?, ?)");
|
||||
$stmt_cat->bind_param("si", $new_category_name, $current_user_id);
|
||||
if($stmt_cat->execute()){ $category_id = $conn->insert_id; }
|
||||
$stmt_cat->close();
|
||||
$stmt_check = $conn->prepare("SELECT id FROM categories WHERE name = ? AND user_id IN ($placeholders)");
|
||||
$check_params = array_merge([$new_category_name], $household_member_ids);
|
||||
$stmt_check->bind_param("s" . $types, ...$check_params);
|
||||
$stmt_check->execute();
|
||||
$res_check = $stmt_check->get_result();
|
||||
if ($res_check->num_rows > 0) {
|
||||
$category_id = $res_check->fetch_assoc()['id'];
|
||||
} else {
|
||||
$stmt_cat = $conn->prepare("INSERT INTO categories (name, user_id) VALUES (?, ?)");
|
||||
$stmt_cat->bind_param("si", $new_category_name, $current_user_id);
|
||||
if($stmt_cat->execute()){ $category_id = $conn->insert_id; }
|
||||
$stmt_cat->close();
|
||||
}
|
||||
$stmt_check->close();
|
||||
} else { $category_id = NULL; }
|
||||
} else { $category_id = !empty($_POST['category_id']) ? intval($_POST['category_id']) : NULL; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user