-1

I am trying to insert data into mysql table using python:

add_user = ("INSERT INTO users_new "
                "(first_name, last_name, hire_date, gender, birth_date) "
                "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)")


data_user = ('Ali', 'Ahmed', tomorrow, 'M', date(1977, 6, 14))

cursor.execute(add_user, data_user)

but I have the following error:

cursor.execute(add_user, data_user) File "C:\Python27\lib\site-packages\mysql\connector\cursor.py", line 555, in execute stmt = RE_PY_PARAM.sub(psub, stmt) File "C:\Python27\lib\site-packages\mysql\connector\cursor.py", line 86, in call "Not enough parameters for the SQL statement") ProgrammingError: Not enough parameters for the SQL statement

  • 1
    What is `add_employee`? Or `data_employee`, you've not shown either. – roganjosh Nov 16 '18 at 17:27
  • Guess on the common issue: `cursor.execute(add_employee, (data_employee,))` – roganjosh Nov 16 '18 at 17:28
  • Please provide a complete example without any additional errors other than the one you are asking about. – Code-Apprentice Nov 16 '18 at 17:33
  • sorry , the following is the right code, add_user = ("INSERT INTO users_new " "(first_name, last_name, hire_date, gender, birth_date) " "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)") data_user = ('Ali', 'Ahmed', tomorrow, 'M', date(1977, 6, 14)) cursor.execute(add_user, data_user) – iman hassoon Nov 16 '18 at 17:51

1 Answers1

0

Hard to know exact reason for that error without seeing code for add_employee and data_employee. But in your add_user and add_group it looks like you forgot to add the actual strings to format %s and %()s?

EDIT after clarification:

The problem is that you provide 8 when you really need 5 %s. Date is just one argument.

add_user = ("INSERT INTO users_new "
                "(first_name, last_name, hire_date, gender, birth_date) "
                "VALUES (%s, %s, %s, %s, %s)")


data_user = ('Ali', 'Ahmed', tomorrow, 'M', date(1977, 6, 14))

cursor.execute(add_user, data_user)
Ricky Kim
  • 1,992
  • 1
  • 9
  • 18
  • sorry , this is the right code,add_user = ("INSERT INTO users_new " "(first_name, last_name, hire_date, gender, birth_date) " "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)") data_user = ('Ali', 'Ahmed', tomorrow, 'M', date(1977, 6, 14)) cursor.execute(add_user, data_user) – iman hassoon Nov 16 '18 at 17:53