0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
RageZ
  • 177
  • 1
  • 7
  • `c.execute("INSERT INTO Players VALUES (NULL, ?)", (nickname,))` – sahasrara62 Nov 02 '20 at 15:33
  • Does this answer your question? [sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 74 supplied](https://stackoverflow.com/questions/16856647/sqlite3-programmingerror-incorrect-number-of-bindings-supplied-the-current-sta) – sahasrara62 Nov 02 '20 at 15:33

1 Answers1

3

it should be

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

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

buran
  • 13,682
  • 10
  • 36
  • 61