我试图在MySQL数据库中存储项目、URL和价格,并希望用户能够根据名称删除项目。我试图通过使用DELETE sql语句来实现这一点,但它只返回“0 item removed”,我猜它无法找到条目,不管是它没有接受输入还是什么。任何帮助都将不胜感激,因为我真的很想掌握这个窍门
def deleteItem():
goneItem = input("Enter item: ")
removeItem = "DELETE FROM amazon_items WHERE itemName = '%s'"
mycursor.execute(removeItem, goneItem)
db.commit()
print(mycursor.rowcount, "item removed")
尝试删除
%s
周围的单引号,您应该将%s
的值作为元组传递嗨,LearningCode欢迎来到stackoverflow
试试这个
您可以在文档的here中看到,您需要包含一个逗号,以使第二个参数成为元组
相关问题 更多 >
编程相关推荐