Samuel Stubbings Samuel Stubbings - 5 months ago 41
Python Question

sqlite3.InterfaceError and query error

I'm using SQLITE3 in python and I have a couple errors.

First one:

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

Second one:
This one isn't an ERROR per say, but none the less It doesn't work.

username= input("Username: ").lower()
password= input("Password: ")

#Get username and see if it exists
c.execute('SELECT id FROM accounts WHERE username=?', (username))

#Insert values into the account table in the database.
c.execute("INSERT INTO accounts VALUES(NULL,?,?)", (username,password))


#Grab ID
ids = c.execute("SELECT id FROM accounts WHERE username=?", (username,))

#Insert defaults into playlists
c.execute("INSERT INTO playlists VALUES(NULL,?,'NULL')", (ids))

#Save the changes.

All it does is say "Account with that username already exists!" and the only account is

Username: s
Password: s

I've looked around on StackOverflow but couldn't find anything that helped my cause, hence why I'm posting this.

def loggedIn(userid):
def viewPlaylist(userid):
print(userid + 1)
c.execute("SELECT 1 FROM playlists where userid=?", (userid))

printError("ERROR: No Data found, with that UserID\nCreating Data...")
c.execute("INSERT INTO playlists VALUES(NULL,?,NULL)", (userid))
printError("Finished!\nYou may now edit your playlist.")

Answer Source

This from my side:

def logged_in(user_name, password):
    # Here you should add conn and cursor, or paste in parameter
    c.execute("SELECT id FROM accounts where username=? and password=?", (user_name, password)))
    user = c.fetchone()
    if user:
        print('logged in')
        print('user not found')

Or in your way, you should make so:

loggedIn(c.execute("SELECT id FROM accounts where username=?",(username)).fetchone())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download