[英]How do I correctly specify the WHERE clause in this SQL query written in PHP?
$query = "INSERT INTO directory_level_one (child_categories)
VALUES
('$category_name')
WHERE
category = '$parent'";
當前,在上述sql查詢中添加WHERE部分時,出現以下錯誤。
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE category = 'Philosophy'' at line 4
您不能在Insert語句中使用where子句。 您是否要更新現有的數據庫記錄? 在這種情況下,請使用Update語句。
您不能在插入語句中使用where子句。
在INSERT語句中不能使用where子句
請先閱讀此內容,然后再繼續http://dev.mysql.com/doc/refman/5.5/zh-CN/insert.html
您要做的是:
$query = "UPDATE directory_level_one SET child_categories='$category_name' WHERE category = '$parent'";
我認為您可能想將INSERT
更改為UPDATE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.