Py学习  »  Python

Python SQlite3更新无错误,但不更新

Marcus • 3 年前 • 1055 次点击  

它没有显示错误,可以运行,但SQLite表中的数据不会更新。然而,其他更新功能类似于这项工作

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
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/128816
 
1055 次点击  
文章 [ 1 ]  |  最新文章 3 年前
forpas
Reply   •   1 楼
forpas    3 年前

参数的第二个参数的元组中参数的顺序 cursor.execute() 必须与 ? 起搏器:

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