我正在尝试将数据添加到在tkinter GUI上收集的表中。该错误不断出现:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection_cext.py", line 489, in cmd_query raw_as_string=raw_as_string) _mysql_connector.MySQLInterfaceError: 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 'Rank,Email,Phone) VALUES(5509,'mandy123','password123','Mike','Andy','MJR','mand' at line 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__ return self.func(*args) File "C:\Users\xande\OneDrive\Desktop\School\YR 14\CCF program\CCF code.py", line 146, in addldrsubmit mycursor.execute(insertSQL,(LID,str(lunentry),str(lpwentry),str(lfnentry),str(lsnentry),str(lrankentry),str(lemailfullentry),lphoneentry,)) File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\cursor_cext.py", line 266, in execute raw_as_string=self._raw_as_string) File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection_cext.py", line 492, in cmd_query sqlstate=exc.sqlstate) mysql.connector.errors.ProgrammingError: 1064 (42000): 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 'Rank,Email,Phone) VALUES(5509,'mandy123','password123','Mike','Andy','MJR','mand' at line 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()
答案 0 :(得分:1)
根据您提供的描述,我想这是使用RANK作为列名。它是reserved keyword。您可以尝试this solution-使用反引号。
但是,如果发生了其他情况,您可以提供更多信息,如评论中所述。表定义,完整的SQL,您正在尝试执行。