S
S
samperirrrrr2020-12-11 17:22:09
Python
samperirrrrr, 2020-12-11 17:22:09

Why do I have an error? programming error?

Hello everyone, why am I getting an error? What is the problem?

def rang(user_id):
  connection = connect()
  user_data = lox(user_id)
  try:
    with connection.cursor() as  cursor:
      result = cursor.execute(f'SELECT * FROM  accounts WHERE uid={user_id}')
      row = cursor.fetchone()
      if user_data["plus"] >= 10:
        user_data["rang"] += " sharingan"
        cursor.execute(f'UPDATE accounts SET rang={user_data["rang"]} WHERE uid={user_id}')
        connection.commit()
  finally:
    connection.close()

ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'rank sharingan WHERE uid=576167340' at line 1")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-12-11
@samperirrrrr

1) No need to use f strings to form SQL:

f'UPDATE accounts SET rang={user_data["rang"]} WHERE uid={user_id}'

2) SET rang='some value' - missing quotes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question