I'd like the field I am inserting the data into to be a variable. And though there are plenty of questions on passing VALUES through variables there isn't a lot on passing column names.
ppg = [22.6]
import mysql.connector
mydb = mysql.connector.connect(host="localhost",
user="root",
password="#########",
database="#########")
mycursor = mydb.cursor()
command = (
"INSERT INTO table1({t_dot}) where id = 2"
"VALUES(%s)"
)
data = (float(ppg))
mycursor.execute(command.format(t_dot = 'Stats 1 Column'),data)
mydb.commit()
mycursor.close()
mydb.close()
The database has an id column which also serves as the primary key.
I'm currently getting
ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use