将Python代码与MySQL连接时出现回溯错误

时间:2019-04-09 12:03:52

标签: python mysql

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Users\harsh\Desktop\index.py", line 33, in Login
    cursor.execute("SELECT * FROM `member` WHERE `username` = text AND `password` = ?", (USERNAME.get(), PASSWORD.get()))
  File "C:\Program Files\Python37\lib\site-packages\mysql\connector\cursor_cext.py", line 261, in execute
    "Not all parameters were used in the SQL statement")
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement

2 个答案:

答案 0 :(得分:0)

尝试一下:

cursor.execute("SELECT * FROM `member` WHERE `username` = %s AND `password` = %s", (USERNAME.get(), PASSWORD.get()))

答案 1 :(得分:0)

您的sql执行查询中有一个错误,如果您要在字段中传递,则应该知道如何很好地进行字符串格式化。 例如,您编写的代码应该以这种方式编写

query = "SELECT * FROM `member` WHERE `username` = {} AND 
`password` = {}".format (USERNAME.get(), PASSWORD.get())
cursor.execute(query)

由于您只用一行编写整个查询,因此请尝试使用上述更正进行调整。