I want to check if the username exist in the table or not.The code is working when i select everything from the table but i get a error when i only try username.The error i get is
File "\Python\Python37\lib\tkinter__init__.py", line 1705, in call return self.func(*args)
File /Calculator_calorie/login_register.py", line 89, in create
login_backend.insert(self.namere_text.get(),self.passwordr1e_text.get())
File \Calculator_calorie\login_backend.py", line 18, in insert
if cur.execute('SELECT name FROM user WHERE name = ?',(name)):
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 4 supplied.
import sqlite3
from tkinter import *
from tkinter import messagebox
from user import user
def connect():
conn=sqlite3.connect("login.db")
cur=conn.cursor()
cur.execute("CREATE TABLE if NOT exists user(name text,password text)")
conn.commit()
conn.close()
def insert(name,password):
conn=sqlite3.connect('login.db')
cur = conn.cursor()
if cur.execute('SELECT * FROM user WHERE name = ?', (name)):
if cur.fetchone():
messagebox.showinfo('Error', 'User already exist')
else:
cur.execute('INSERT INTO user VALUES(?,?)', (name, password))
messagebox.showinfo('Register', 'Entry sucess')
conn.commit()
conn.close()
def create(self):
if self.passwordr1e.get() != self.passwordr2e.get():
messagebox.showinfo('error','Passwords do not match')
elif len(self.namere.get()) == 0:
messagebox.showinfo('error', 'Name field is empty')
elif len(self.passwordr1e.get()) == 0:
messagebox.showinfo('error', 'PASSWORD field is empty')
else:
login_backend.insert(self.namere_text.get(),self.passwordr1e_text.get())