Reputation: 5477
I'm trying to insert data into my database and I get a MYSQL syntax error using this code:
import MySQLdb
db=MySQLdb.connect(host="localhost",user="root",passwd="",db="database")
cursor = db.cursor()
sql = "INSERT INTO table1('col1','col2') values ('val1','val2');"
cursor.execute(sql)
db.commit()
Upvotes: 1
Views: 1252
Reputation: 17537
No quotes around the column names.
INSERT INTO table1(col1, col2) VALUES ('val1', 'val2');
You could use backticks around the column names, but not single quotes.
Upvotes: 2