0 votes
1 view
in SQL by (6.1k points)

I am getting an error on the following Python code:

import mysql.connector

cnx = mysql.connector.connect(user='root', password='',



cursor = cnx.cursor()

Name = "James"

Department = "Finance"

StartYear = 2001

CurrentPos = 2001

Link = ""

add_user = ("INSERT INTO DB.tbluser "

       "(username, department, startyear, currentpos, link) "

       "VALUES (%s, %s, %d, %d, %s)")

data_user = (Name, Department, StartYear, CurrentPos, Link)

cursor.execute(add_user, data_user)




The error message is, 

mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement 

 Can anyone help with this?

1 Answer

0 votes
by (12.7k points)
edited by

The parameter marker is %s not %d.

add_user = """INSERT INTO DB.tbluser 

              (username, department, startyear, currentpos, link) 

              VALUES (%s, %s, %s, %s, %s)"""

Note that the parameter markers used by mysql.connector may seem to be the same like the %s used in the Python string formatting however the relationship is only coincidental. Some database adapters like oursql and sqlite3 use the  ? as the parameter marker instead of the %s.

Want to be a SQL expert? Join this SQL Certification course by Intellipaat.

You can check out the below MySQL Tutorial video for better understanding.

Related questions

0 votes
1 answer
0 votes
1 answer
+2 votes
1 answer
0 votes
1 answer
asked Jul 6, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Oct 19, 2020 in SQL by dev_sk2311 (31.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !