【发布时间】:2020-10-19 08:55:54
【问题描述】:
我正在尝试将数据添加到在 tkinter GUI 上收集的表中。这个错误不断出现:
Tkinter 回调中的异常 回溯(最近一次通话最后): 文件“C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection_cext.py”,第 489 行,在 cmd_query raw_as_string=raw_as_string) _mysql_connector.MySQLInterfaceError:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 'Rank,Email,Phone) VALUES(5509,'mandy123','password123','Mike','Andy','MJR','mand ' 在第 1 行 在处理上述异常的过程中,又出现了一个异常: 回溯(最近一次通话最后): 文件“C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py”,第 1705 行,在 __call__ 返回 self.func(*args) 文件“C:\Users\xande\OneDrive\Desktop\School\YR 14\CCF program\CCF code.py”,第 146 行,在 addldrsubmit mycursor.execute(insertSQL,(LID,str(lunentry),str(lpwentry),str(lfnentry),str(lsnentry),str(lrankentry),str(lemailfullentry),lphoneentry,)) 执行中的文件“C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\cursor_cext.py”,第 266 行 raw_as_string=self._raw_as_string) 文件“C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection_cext.py”,第 492 行,在 cmd_query sqlstate=exc.sqlstate) mysql.connector.errors.ProgrammingError: 1064 (42000): 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 'Rank,Email,Phone) VALUES(5509,'mandy123','password123','Mike','Andy','MJR','mand ' 在第 1 行我使用的代码是:
import mysql.connector
if True:
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="abarclay172",
database="rbaiccf"
)
mycursor=mydb.cursor()
LID = random.randint(1000,9999)
lunentry = lunentrye.get()
lpwentry = lpwentrye.get()
lfnentry = lfnentrye.get()
lsnentry = lsnentrye.get()
lrankentry = addldrranke.get()
lemailentry = lemailentrye.get()
lemailaddressentry = addldremailaddresse.get()
lemailfullentry = lemailentry + lemailaddressentry
lphoneentry = "+44" + lphoneentrye.get()
insertSQL="""INSERT INTO leader(leaderID,Username,Password,Forename,Surname,Rank,Email,Phone) VALUES(%s,%s,%s,%s,%s,%s,%s,%s)"""
mycursor.execute(insertSQL,(LID,str(lunentry),str(lpwentry),str(lfnentry),str(lsnentry),str(lrankentry),str(lemailfullentry),lphoneentry,))
mydb.commit()
【问题讨论】:
-
你需要共享表
leader定义。 -
为什么在将
insertSQL传递给execute之前不打印它?这样你就可以看到它在做什么? -
请修正代码的缩进。使用反引号 (`) 排名作为列名,它可能会解决问题。
标签: python mysql python-3.x tkinter