当我继续运行以下查询时:
$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号,
to =一个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注入,您应该考虑使用准备好的语句。