我正在尝试使用下面的功能更新个人详细信息表,但它没有更新。它显示该人员的详细信息已成功更新,但内容保持不变。
#======= Update Function =================
def update_data(self):
if self.var_Gender.get()=="Select Gender" or self.var_FirstName.get()=="" or self.var_LastName.get()=="" or self.var_Nationality.get()=="" or self.var_HomeAddress.get=="" or self.var_Occupation.get=="":
messagebox.showerror("Error","All fields are required",parent=self.root)
else:
try:
Update=messagebox.askyesno("Update","Do you want to update this person's details",parent=self.root)
if Update>0:
conn=mysql.connector.connect(host="localhost",username="root",password="tupsy@5050",database="details")
my_cursor=conn.cursor()
my_cursor.execute(
"update intel set Gender=%s,FirstName=%s,LastName=%s,Nationality=%s,Occupation=%s,HomeAddress=%s,PhoneNo=%s,Email=%s where Nationality=%s",
(
self.var_Gender.get(),
self.var_FirstName.get(),
self.var_LastName.get(),
self.var_Nationality.get(),
self.var_Occupation.get(),
self.var_HomeAddress.get(),
self.var_PhoneNo.get(),
self.var_Email.get(),
self.var_radio2.get()
)
)
else:
if not Update:
return
messagebox.showinfo("success","Person's details successfully updated",parent=self.root)
conn.commit()
self.fetch_data()
conn.close()
except Exception as es:
messagebox.showerror("Error",f"Due To:{str(es)}",parent=self.root)
我试着检查所有参数,但它们都很好
1条答案
按热度按时间xt0899hw1#
在查询中,尝试用双引号
\"\"
将所有字符串占位符括起来。反斜杠对于转义字符串中的双引号是必需的。