0

I'm trying do delete a user from my database using python and sqlite.

import sqlite3
database_connection = sqlite3.connect('test.db')
delete_username_input = input("Which user you would like to delete?\n\n")
sql = ("DELETE * from USERS where USERNAME = ?")
args = (delete_username_input)
database_connection.execute(sql, args)
database_connection.commit()
database_connection.close()

When running the code above, I get the following error:

sqlite3.OperationalError: near "*": syntax error

Any idea what might be causing this error?

The table that I use has been created using the following syntax:

conn.execute('''CREATE TABLE USERS
 (ID INTEGER PRIMARY KEY AUTOINCREMENT,
 USERNAME TEXT NOT NULL,
 PASSWORD TEXT NOT NULL,
 WINS FLOAT NOT NULL,
 LOSES FLOAT NOT NULL,
 GAMESPLAYED FLOAT NOT NULL,
 WINPERCENT FLOAT NOT NULL );''')

Any help will be appreciated.

asked Aug 2, 2017 at 8:16

1 Answer 1

1

Your SQL syntax is wrong. It should be

DELETE from USERS where USERNAME = ?

without the *

Check it out here

answered Aug 2, 2017 at 8:17
Sign up to request clarification or add additional context in comments.

1 Comment

Yes that's it, thank you. Also the database_connection.execute(sql, args) should've been database_connection.execute(sql, (args,)).

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.