我正在尝试使用 Python 和 SQLite 更新我的用户详细信息。
目标是一次性升级我用户的所有栏目。
我的代码是:
def update():
new_username = input("Input your NEW username:\n")
new_firstname = input("Input your NEW firstname:\n")
new_lastname = input("Input your NEW lastname:\n")
new_email = input("Input your NEW email:\n")
new_password = input("Input your NEW password:\n")
update_customer =("""UPDATE customer SET username = ? AND firstname = ? AND lastname = ? AND email = ? AND password = ?""")
cursor.execute(update_customer, [(new_username), (new_firstname), (new_lastname), (new_email), (new_password)])
我在运行 python 函数之前和之后检查了数据库。但是,更改不会保存到数据库中。除了消失的用户名之外什么都没有改变。
最佳答案
您不能使用 AND 来设置其他列。相反,您可以使用逗号分隔要设置的列。
所以你想要
update_customer =("""UPDATE customer SET username = ?, firstname = ?, lastname = ?, email = ?, password = ?""")
如果没有将所有行设置为相同的值,则使用 WHERE 子句。
根据:-
关于python - 更新多列: the Username disappears,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53891137/