0

我正在尝试通过带有 web.py 的表单 POST 更新数据库行,但出现 MySQL 语法错误。我一般是 Python 新手,所以请原谅我的新手问题。这是我正在运行的代码:

   def Update(webInput):
      db.update('category', where='category_name=' + webInput.category_name)
      return;

我得到的错误是

ProgrammingError: (1064, "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_name=' at line 1")

谢谢

4

2 回答 2

1

检查db.update 的文档。正确的调用是:

db.update('category', where='category_name = $category_name', vars=webInput, **webInput)

假设webInput持有要设置的新数据。

$category_name在 where 子句中提取vars和清理(即使您的代码有效,它也容易受到 sql 注入的攻击)。

于 2012-11-23T13:28:36.040 回答
0

看起来您忘记传递要更新“类别”的数据。

尝试:

db.update('category', where='category_name=' + webInput.category_name, 'new data here')
于 2012-11-23T02:46:19.967 回答