1

What is wrong in the following code syntax

cur.execute('INSERT INTO %s (%s) VALUE (%s)' % (table, Column, Value))
0

The following works on my version of Python. In my opinion, there is a problem with the string. Update your cur.execute() accordingly.

>> Table = "Kutta"

>> Column = "Says"

>> Value = "Bhow"

>> FINAL_STRING = "INSERT INTO " + Table + " (" + Column + ") VALUE (" + Value + ")"

>> FINAL_STRING

'INSERT INTO Kutta (Says) VALUE (Bhow)'

2
  • > Table = "Sheet1" > Column = "Description" > Value = "GoodMorning" > FINAL_STRING = "INSERT INTO " + Table + " (" + Column + ") VALUE (" + Value + ")" > cur.execute(FINAL_STRING) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute self.errorhandler(self, exc, value) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.OperationalError: (1054, "Unknown column 'GoodMorning' in 'field list'") – Tamal Chakraborty May 31 '15 at 11:35
  • Your FINAL_STRING should work. – Tamal Chakraborty Jun 1 '15 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.