Python中的MySQL错误

2024-06-26 13:46:05 发布

您现在位置:Python中文网/ 问答频道 /正文

I need to insert a record into the table MemberDetails but I end up with the error stating " _mysql_exceptions.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 'I' at line 1") "

sql5="INSERT INTO MemberDetails VALUES"+"("+"'2016-2020','"+PhoneNum+"','VEC','"+Address+"','"+StuID+"','"+DOB+"','1000','"+Name+"','"+Pass+"','"+dept+"','"+year+"','"+sec+"')"    
cursor.execute(sql5)

Tags: thetoyourtableerrorneedrecordbut
1条回答
网友
1楼 · 发布于 2024-06-26 13:46:05

您需要在表中添加间距以及每个变量将插入的列,您的查询应如下所示:

"INSERT INTO MemberDetails (datetime, phone, code, address, stuid, birthdate, num, name, pass, dept, year, sec) VALUES (" + "'2016-2020','" + PhoneNum + "','VEC','" + Address + "','" + StuID + "','" +DOB +"','1000','" + Name + "','" + Pass + "','" + dept + "','" + year + "','" +sec + "')" 

只需将第一组括号中的变量替换为您希望每个变量放入的列名。你知道吗

相关问题 更多 >