0

can someone help?

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\huzey\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection_cext.py", line 506, in cmd_query
_mysql_connector.MySQLInterfaceError: 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 ')' at line 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\huzey\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "c:\Users\huzey\OneDrive\Masaüstü\gui\loginsystem.py", line 198, in add_customer
    my_cursor.execute(sql_command, values)
  File "C:\Users\huzey\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor_cext.py", line 269, in execute
    result = self._cnx.cmd_query(stmt, raw=self._raw,
  File "C:\Users\huzey\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection_cext.py", line 510, in cmd_query
    raise errors.get_mysql_exception(exc.errno, msg=exc.msg,
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 ')' at line 1

this is the full error and this is the part of the code that have error:

def add_customer():
    sql_command = "INSERT INTO customers (first_name, last_name, addres, phone, email, age, country, rent) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, )"
    values = (first_name_box.get(), last_name_box.get(), address_box.get(), phone_box.get(), email_box.get(), age_box.get(), country_box.get(), rent_box.get())
    my_cursor.execute(sql_command, values)
    mydb.commit()
    clear_all()

btw im tryng to make a real estate managment system. if you have any idea im open to new ideas and about the code i can give details if you want.

1
  • btw, there's a typo in your code: addres (should be address) Commented Jul 15, 2021 at 12:18

1 Answer 1

2

You have an extra comma at the end:

... VALUES (%s, %s, %s, %s, %s, %s, %s, %s, )

Get rid of that – and while you're at it, you can split the statement into multiple literals for more readability:

sql_command = (
    "INSERT INTO customers "
    "(first_name, last_name, addres, phone, email, age, country, rent) "
    "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
)
Sign up to request clarification or add additional context in comments.

2 Comments

thank you the first error is gon but now i have another error like this: Unknown column 'addres' in 'field list' ... and the error is in this line: my_cursor.execute(sql_command, values)
Try address instead.

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.