I am attempting to insert data into a MySQL database. I am using python 2.7 and I am using the mysql.connector.
My error is:
mysql.connecto
I was getting same error and while searching for its solution I stumbled upon this question after several attempts I was able to resolve. The mistake was a typing error for column name in WHERE
clause of UPDATE
statement. My column name was 'ROLL_NO' instead I had typed 'ROLL_NO.'
Please look to this point as well.
str parameter in SQL query must by in quote 'str'.
So, need use '%s' with ' ' for str, and %s without ' ' for numbers:
cursor.execute("""INSERT INTO db_name (str,int,str,int)
VALUES ('%s', %s, '%s', %s)""" % (str,int,str,int))
cnx.commit()
mycursor.execute("insert into table_name(column) values(%s)"%data_variable)
I think the issue here might be the semicolon at the end of the query.
Have a good day.
I had the same issue with the single parameter statement, this worked:
mycursor.execute("INSERT INTO cust (user) VALUES(%s)" % (username))
Try this
SQLInsertCmd = """INSERT INTO
TestNounPhrase (NPhrase) VALUES ((%s))""" % (np)
cursor.execute(SQLInsertCmd)