首先,我必须承认我是Python和SQL的新手。现在,我会解决问题。我正在尝试更新column_ID等效于变量的表。在Python类中,我有一个带有以下语句的函数:
stName = self.txtName.text()
stUsername = self.txtUsername.text()
stPassword = self.txtPassword.text()
stMobile = self.txtMobile.text()
myID = self.txtID.text()
sql_update_query = """UPDATE signup SET name = %s, username = %s, password = %s, mobile = %s WHERE id = myID"""
input = (stName, stUsername, stPassword, stMobile)
curs.execute(sql_update_query, input)
conn.commit()
当我单击“更新”按钮以运行此功能时,系统提示“ Python已停止工作”。
有人可以协助我修复SQL语句吗?
答案 0 :(得分:1)
myID
需要作为参数传递给sql语句。
sql_update_query = """UPDATE signup SET name = %s, username = %s, password = %s, mobile = %s WHERE id = %s"""
还有
input = (stName, stUsername, stPassword, stMobile, myID)