1
votes

I have implemented most other basic database transactions including insert,update,select with similar syntax,but on trying to delete,i get error

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1

What would the correct syntax be? I must delete according to user input. Here is a shortened version of my code,minus the insert,select,update part.:

elif (choice == 4):
    mail=raw_input('Enter email of user to be deleted:')
    print 'Deleting..'
    delete_user_details(mail)


def delete_user_details(email):

    sql = "DELETE FROM users WHERE email = %s"
    cursor.execute(sql,email)
1
Is that all of your code? The sql line isn't at line 1 - joel goldstick
Knowing error is on the first line, maybe your connection string has some problems? You should post more. - isamert

1 Answers

4
votes

You need to pass query parameters to cursor.execute() as a tuple, even for a single parameter. Try this:

sql = "DELETE FROM users WHERE email = %s"
cursor.execute(sql, (email,))