【发布时间】:2021-01-16 20:07:54
【问题描述】:
我在通过用户输入更新表中已有的值时遇到了一些问题。当我运行程序时,它会打印出一条声明,说明该项目已成功更新,但它不会更改任何值。 任何帮助都会很棒,因为我的代码似乎没有任何错误,而且我已经坚持了一段时间了。
elif option == "4":
sqlite3.connect('program.db')
inp_ID = int(input("Enter the ID of the item you want to update: "))
itemName = input("Enter New Item Name: ")
itemPrice = input("Enter the items price: ")
itemStock = input("Enter the stock amount of the item: ")
itemDescription = input("Enter a description for the item: ")
updateSQL = "UPDATE items SET itemName = ?, itemPrice = ?, itemStock = ?, itemDescription = ? WHERE " \
"itemID = ? "
conn.execute(updateSQL, (inp_ID, itemName, itemPrice, itemStock, itemDescription))
conn.commit()
print("Item " + itemName + " has been updated.")
【问题讨论】:
-
您将
inp_ID关联到查询中的第一个占位符(?),即itemName。而是将其移到参数的末尾。