Python 3.x 使用python更新行
所以这里我想写一个python代码来更新一个表。我创建了一个名为customers的表,其中包含一些列。我想更新从用户那里获取输入的列,如果用户没有提供任何输入,我想让它自己获取以前的值。请帮助我,我是python新手Python 3.x 使用python更新行,python-3.x,updating,Python 3.x,Updating,所以这里我想写一个python代码来更新一个表。我创建了一个名为customers的表,其中包含一些列。我想更新从用户那里获取输入的列,如果用户没有提供任何输入,我想让它自己获取以前的值。请帮助我,我是python新手 dummy=[] user_input=int(input("Enter the identification number you want to change:")) First_name=input("Enter the First name:") if len(First
dummy=[]
user_input=int(input("Enter the identification number you want to change:"))
First_name=input("Enter the First name:")
if len(First_name)!=0:
dummy+="Firstname="+First_name
cursor.execute("update customer4 set Firstname=? where identification=?")
values=(dummy,user_input)
conn.commit
Last_name=input("Enter the last name:")
if len(Last_name)!=0:
if len(First_name)!=0:
dummy+="Firstname"+First_name, "Lastname"+Last_name
cursor.execute("update customer4 set Firstname=?, Lastname=? where identification=?")
values=(dummy,user_input)
conn.commit
else:
dummy+="Lastname"+Last_name
cursor.execute("update customer4 set Lastname=? where identification=?")
values=(dummy,user_input)
conn.commit
print(cursor.rowcount,"record affected")
这是我的python代码。请帮我学习python。execute()行的语法错误。使用“?”作为placehoder是正确的方法,但您的值需要像这样插入:
cursor.execute("update customer4 set Firstname=? where identification=?", (dummy,user_input))
execute()行的语法错误。使用“?”作为placehoder是正确的方法,但您的值需要像这样插入:
cursor.execute("update customer4 set Firstname=? where identification=?", (dummy,user_input))
我像这样更改了代码。它正在执行但没有更新。我哪里出错了
我像这样更改了代码。它正在执行,但没有更新。我哪里出错了?query1=(“更新客户4 set Firstname=?,Lastname=?,Email=?,Phoneno=?)其中identification=?)
括号()
你已经关门两次了。
删除该Phoneno=?)后面的右括号“)查询1=(“更新客户4设置Firstname=?,Lastname=?,Email=?,Phoneno=?),其中标识=?”)
括号()
你已经关门两次了。
删除该Phoneno=?)之后的右括号“)”