[英]MySQLi query error while running
當我繼續運行以下查詢時:
$sql3 = mysqli_query($con, 'INSERT INTO berichten (from, naar, file) VALUES ('.$id.', '.$to.', "'.$url.'")') or die(mysqli_error($con));
我會收到此錯誤:
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 'from, naar, file) VALUES (2, 2, "b9173a1b9ade8767280009f9638bd987.caf")' at line 1
id =一個ID號,
到=一個ID號,然后
url =文件名(例如sound.caf)
為什么會出現此錯誤以及如何解決?
謝謝!
from
是一個特殊的SQL關鍵字。 您必須通過將其放入反引號來對其進行轉義:
$sql3 = mysqli_query($con, 'INSERT INTO berichten (`from`, naar, file) VALUES ('.$id.', '.$to.', "'.$url.'")') or die(mysqli_error($con));
除此之外,您可能需要像對$url
一樣引用ID
和file
。
順便說一句。 您應該真正考慮使用准備好的語句,以防止SQL注入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.