Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm looking to insert the ID of the current user into a table called Orders in my SQLite database

results is a variable that represents the current user that is logged in and looks like this:

existingAccount = input("Do you already have an account? (y/n)")
if existingAccount == "y":
    username = input("Please enter your username: ")
    password = input("Please enter your password:")

    find_user = "SELECT * FROM Users WHERE Username = ? AND Password = ?"
    c.execute(find_user, [username, password])
    results = c.fetchall()

later on this variable is checked to see if the user is an admin to allow them to perform certain functions using results[0][3], the third column being the permission level.

My original idea was to use results[0][0] to fetch the ID and to add it to the table:

shopping = True
while shopping:

    itemToAdd = input("Please enter the ID of the item to add to the basket: ")
    basket.append(itemToAdd)
    print(basket)
    continueShop = input("Continue shopping?(y/n): ")
    if continueShop == "n":
        conn.execute("INSERT INTO Orders (UserID) VALUES = (?)", (results[0][0]))
        conn.commit()

Printing results[0][0] gives me the ID as I want however I am not able to insert it into the table and am given this when debugging.

debugger


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
690 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...