0

The Python MySQL.connector keeps giving me the error Not all parameters used in the SQL statement. This is my code:

import mysql.connector

con = mysql.connector.Connect(user='root', password='password', database='DB', host='localhost')
cur = con.cursor()

#data inserter
add_data = "INSERT INTO DB.verkiezing (jaar, kamer, opkomst1, opkomst2, thema, gemeente, provincie, winnaar, VVD, PvdA, PVV, SP, CDA, D66, ChristenUnie, GROENLINKS, SGP, PvdD, 50Plus, OndernemersPartij, VNL, Denk, NieuweWegen, FvD) VALUES ($s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s, $s)"

#data
testvar = ('2017', "'Tweede", '81.9', '85.8', 'Identiteit', "'s-Gravenhage", 'Zuid-Holland', 'VVD', '33.0', '9.0', '20.0', '14.0', '19.0', '19.0', '5.0', '14.0', '3.0', '5.0', '4.0', '0.0', '0.0', '0.0', '0.0', '3.0')

cur.execute(add_data, testvar)
con.commit()

cur.close()
con.close()

The error pops up even though the number of %s and the number of columns match. If I try to do the same operation in MySQL itself, like so:

USE DB;
INSERT VALUES INTO verkiezing (jaar, kamer, opkomst1, opkomst2, thema, gemeente, provincie, winnaar, VVD, PvdA, PVV, SP, CDA, D66, ChristenUnie, GROENLINKS, SGP, PvdD, 50Plus, OndernemersPartij, VNL, Denk, NieuweWegen, FvD) VALUES ('2017', "Tweede", '81.9', '85.8', 'Identiteit', "'s-Gravenhage", 'Zuid-Holland', 'VVD', '33.0', '9.0', '20.0', '14.0', '19.0', '19.0', '5.0', '14.0', '3.0', '5.0', '4.0', '0.0', '0.0', '0.0', '0.0', '3.0');

It works, no problem. What am I doing wrong in Python? I use Python 3.6.1 and MySQL 14.14 Distrb 5.7.14. Thank you in advance

MSDMMM
  • 41
  • 5
  • 1
    I see lots of `$` but not a single `%` – e4c5 May 11 '17 at 07:02
  • Possible duplicate of [Not all parameters were used in the SQL statement (Python, MySQL)](http://stackoverflow.com/questions/20818155/not-all-parameters-were-used-in-the-sql-statement-python-mysql) – user3382203 May 11 '17 at 07:06
  • @ e4c5: you nailed it... I tried everything but look accurately enough at my code it seems. Thanks a million! – MSDMMM May 11 '17 at 07:13

0 Answers0