.py文件中的代码:
cur = mysql.connection.cursor()
# Check if this user had voted for somebody
is_voted = cur.execute("SELECT TUTOR_VOTED FROM USERS WHERE USERNAME="+str(session["username"]))
session["username"]
保留用户cookie。我已经登录的用户名为“ admin”
但是is_voted内部的MySQL命令可能有问题
错误:
MySQLdb._exceptions.OperationalError: (1054, "Unknown column 'admin' in 'where clause'")
但是我在使用时得到了正确的返回值
SELECT TUTOR_VOTED FROM USERS WHERE USERNAME='admin'
is_voted中的输入格式是否有问题?
答案 0 :(得分:1)
您的组合"SELECT TUTOR_VOTED FROM USERS WHERE USERNAME="+str(session["username"])
的输出字符串缺少一对单引号''
。您可以将其更改为:
is_voted = cur.execute("SELECT TUTOR_VOTED FROM USERS WHERE USERNAME='%s'" % str(session["username"]))