This question has been asked bevor (here), but no answer is working for me and unfortunally I am not allowed to add a comment, because I'm new here. I didn't know what else to do than asking the question again, sorry for this - please tell me the right way to do.
I want to insert Python variables into a MySQL table named by a Python variable. I figured out, to create the table by:
curs.execute ("""CREATE TABLE IF NOT EXISTS %s LIKE table""" %(today))
I also figured out to insert values like this:
curs.execute (
""" INSERT INTO table (column)
VALUES (%s) """,
(variable))
Now I tried
today = "table_name"
variable = "name"
curs.execute (
""" INSERT INTO %s (column)
VALUES (%s) """,
( table, variable ))
I'll get this error:
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''table_name' (column …' at line 1")
I also tried:
today = "table_name"
variable = "name"
curs.execute (
""" INSERT INTO %s (column)
VALUES (%s) """
% ( table, variable ))
I'll get this error:
(1054, "Unknown column 'name' in 'field list'")
I guess there's something wrong with the strings …
Thank you for answers!