RageZ
RageZ

Reputation: 197

Python SQLite insert data with variable

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

Upvotes: 0

Views: 339

Answers (1)

buran
buran

Reputation: 14233

it should be

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

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

Upvotes: 3

Related Questions