0
votes

I am currently working on a gym membership system in tkinter and sqlite3. I have this ongoing error and I do not know what is wrong. I cannot figure out why there is an incorrect number of bindings supplied.

def new_user(self):
    #Establish Connection
    with sqlite3.connect('Gym.db') as db:
        c = db.cursor()

    #Find Existing username if an action is taken

    find_user = ('SELECT * FROM member WHERE username = ?')
    c.execute(find_user,[(self.n_Username.get())])
    if c.fetchall():
        ms.showerror('Error!','Username Taken Try a Diffrent One.')

    else:
        ms.showinfo('Success!','Account Created!')
        self.main_page()

    sql = "INSERT INTO 'Member' (FirstName,LastName,Email,Phone,Balance,Username,Password) VALUES(?,?,?,?,?,?,?)" #<-------
    c.execute(sql,[(self.n_FirstName.get(),self.n_LastName.get(),self.n_Email.get(),self.n_Phone.get(),self.n_Balance.get(),self.n_Username.get(),self.n_Password.get())])
    db.commit()

The error:

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

1

1 Answers

0
votes

You are providing a list containing one tuple as the second argument to the execute method. This leads to the "1 supplied" problem as the tuple within the list counts as just a single binding.

Instead, remove the list and simply pass the contained tuple. i.e.

c.execute(sql,
          [(self.n_FirstName.get(), 
            self.n_LastName.get(),
            self.n_Email.get(),
            self.n_Phone.get(),
            self.n_Balance.get(),
            self.n_Username.get(),
            self.n_Password.get()
          )]
)

should be:

c.execute(sql,
          (self.n_FirstName.get(), 
           self.n_LastName.get(),
           self.n_Email.get(),
           self.n_Phone.get(),
           self.n_Balance.get(),
           self.n_Username.get(),
           self.n_Password.get()
          )
)