0

I'm receiving 'OperationalError: near "VARCHAR": syntax error' when I call this function, what am I doing wrong?

def database_create_user(table_name, user_ID, username, password, creator_exp):
    users_db_curs.execute("INSERT INTO `" + table_name + "` (uID VARCHAR(20), username VARCHAR(20), password VARCHAR(30), creator_exp VARCHAR(20)) VALUES ('" + user_ID + "', '" + username + "', '" + password + "', '" + creator_exp + "')")
    users_db_connection.commit()

2 Answers 2

2

Once the table has already been created, you do not need to re-specify the column types in each INSERT query. You could just do:

users_db_curs.execute("INSERT INTO `" + table_name + "` (user_ID, username , password , creator_exp ) VALUES ('" + user_ID + "', '" + username + "', '" + password + "', '" + creator_exp + "')")
Sign up to request clarification or add additional context in comments.

Comments

2

You shouldn't specify the data types in the INSERT statement. I have removed the data types that appeared in the INSERT statement. Here is the corrected version.

The code is wrapped here into multiple lines for clarity and readability.

def database_create_user(table_name, user_ID, username, password, creator_exp):
users_db_curs.execute("INSERT INTO `" + table_name + "` (uID, username, 
password, creator_exp) VALUES ('" + user_ID + "', '" + username + "', 
'" + password + "', '" + creator_exp + "')")
users_db_connection.commit()

Comments

Your Answer

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.