0
votes

Can't insert variable to sqlite db

def new_player(nickname):
    conn = sqlite3.connect('db/pythonsqlite.db')
    c = conn.cursor()
    c.execute("INSERT  INTO Players VALUES (NULL, ?)", (nickname))
    conn.commit()
    conn.close()
new_player(nickname)

I get this error:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 7 supplied.

7 is the number of letters in nickname string

1
c.execute("INSERT INTO Players VALUES (NULL, ?)", (nickname,)) - sahasrara62

1 Answers

3
votes

it should be

c.execute("INSERT  INTO Players VALUES (NULL, ?)", (nickname,))

this way you supply one-element tuple. Note the comma.