简体   繁体   English

Python SQlite3更新没有报错但是不更新

[英]Python SQlite3 Update No Error But Does Not Updating

It shows no error and is able to run, but the data in the SQLite table doesn't update.它没有显示任何错误并且可以运行,但是 SQLite 表中的数据没有更新。 However other update function similar to this work然而其他更新 function 类似于这项工作

def seller_edit():
    while True:
        sellername = str(input("Enter your username: "))
        with sqlite3.connect(r"C:\Users\User\Desktop\HFSystem\Assginment\HFuserinfo.db") as connect:
            cursor = connect.cursor()
        check = "SELECT * FROM sellerinfo WHERE Username = ?"
        cursor.execute(check,[sellername])

        results = cursor.fetchall()

        if results:
            Phone = int(input("Enter New Phone No.: "))      
            Email = str(input("Enter New Email: "))
            Address = str(input("Enter New Address: "))
      

            updateseller ="""UPDATE sellerinfo SET Phone = ?, Email=?,Address=? WHERE Username=?"""
            
            cursor.execute(updateseller,[sellername,Phone,Email,Address])       
            connect.commit()
            print("Seller Info Edited!")
            connect.close()
            seller_info_menu()
            break

        else:
            print("ProductID does not recognised")
            option = input("Do you want to try again (y/n): ")
            if option.lower() == "n":
                seller_info_menu()
                break

The order of the parameters inside the tuple of the 2nd argument of cursor.execute() must be the same as the order of the ? cursor.execute()的第二个参数元组中的参数顺序必须与? paceholders:步兵:

cursor.execute(updateseller, (Phone, Email, Address, sellername))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM