【发布时间】:2015-03-22 13:05:06
【问题描述】:
我正在使用 PHP、MySQL 和 PHPMyAdmin
以下是 PHP 文件中的代码:
$sql = "INSERT INTO user_login (user_id, email, token)
VALUES ($user_id, $email, $token)";
上述查询出现以下错误:
Error: INSERT INTO user_login (user_id, email, token)
VALUES (303, mrp7590@kastate.edu, 68e1f6cbea3b7a0b77a28395f4a8fef8449c23b1b00a392aa43451a0bfd5ff0e)<br>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 '@kastate.edu, ise152e16e36393037933be10ac8a6f6de9e257a5d85e008bbd379bae20b5f535b)' at line 2
有人可以纠正我在上述插入查询中犯的错误吗?
谢谢。
【问题讨论】:
-
SQL 期望字符串值被引用......但你不应该将值直接注入 SQL 语句,而是使用绑定变量
-
有什么理由不使用准备好的语句?
标签: php mysql sql syntax-error sql-insert