php - 更新时出现SQL错误

标签 php mysql

当我运行 PHP SQL 代码时,出现以下 SQL 错误:

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 useid = 8' at line 1

mysql_query("UPDATE free_ebook SET math = $assign_math WHERE useid = $newuserid;")or die(mysql_error());

math 字段是 int(10)useid 也是 int(10)

最佳答案

看起来字段名称可能应该是 userid,而不是 useid

或者,尝试将值括在单引号中,如下所示:

"UPDATE free_ebook SET math = '".$assign_math."' WHERE useid = '".$newuserid."';"

甚至

"UPDATE free_ebook SET math = '{$assign_math}' WHERE useid = '{$newuserid}';"
<小时/>

关于主题:mysql_query() 已弃用,您应该使用 PDO 扩展。它很容易(也许更容易!)学习并且更安全:

Are there good tutorials on how to use PDO?

http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html

关于php - 更新时出现SQL错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018170/

相关文章:

php - 使用 PHP (PDFLib) 编写 PDF

php - 如何告诉用户数据库中没有用户输入的特定日期的数据

php - 内存缓存在 xampp 中不起作用。找不到类 'Memcache'

python - MySql cursors.execute() 只有一个参数 : Why is a string sliced into a list?

mysql - win7中通过CMD以管理员身份执行命令恢复mysql数据库

php - 使用未定义的常量 REQUEST_URI - 在第 73 行的 functions.php 中假定为 'REQUEST_URI'

php - Twilio 客户端 DTMF 不工作

mysql - 选择 5 行,如果它们不在前 3 行

mysql - 额外提交不会给我任何错误

mysql - mySQL复合主键