如果参数存在,我正在尝试更新此代码,但是,当我执行任何操作时(它确实说已完成,并更新产品,但 products_description 的更新似乎不起作用。代码在这里:
$query = "UPDATE products
SET products_reference='$varenummer', products_price='$pris'
WHERE products_id='$id';";
for ($x = 1; $x <= $amountOfLanguages; $x++) {
$varenavn = $_POST["varenavn-" . $x];
$korttekst = $_POST["korttekst-" . $x];
$langtekst = $_POST["langtekst-" . $x];
$query .= "IF EXISTS (SELECT * FROM products_description WHERE products_id='$id' AND languages_id='$x')
UPDATE products_description
SET products_description_name='$varenavn', products_description_short_description='$korttekst', products_description_description='$langtekst'
WHERE products_id='$id'
AND languages_id='$x'
ELSE
INSERT INTO products_description (products_id, languages_id, products_description_name, products_description_short_description, products_description_description)
VALUES ('$id', '$x', '$varenavn', '$korttekst', '$langtekst');";
}
if ($conn->multi_query($query) === TRUE) {
//header("Location: ./");
//die();
echo "done";
} else {
echo "Error: " . $query . "<br>" . $conn->error;
}
而且我不能真正使用ON DUPLICATE,因为我不知道唯一键,我只知道“products_id”和“languages_id”。
提前致谢。