hello i am new to python, i started learning how to work with mysql but the question arose - how to insert variables into mysql query?
I have code like this now:
table_name = "bot"
variable = 15
mySql_insert_query = """INSERT INTO %s (Id)
VALUES
(%s) """
I try to execute the code, but it gives an error: SyntaxError: EOF while scanning triple-quoted string literal
attempt to call a nil value
How to write the code correctly? thanks
balderman :
Below is an example taken from here.\n...\ncursor = connection.cursor(prepared=True)\nsql_insert_query = """ INSERT INTO Employee\n (id, Name, Joining_date, salary) VALUES (%s,%s,%s,%s)"""\n\ninsert_tuple_1 = (1, "Json", "2019-03-23", 9000)\ncursor.execute(sql_insert_query, insert_tuple_1)\n...\n\nIn your case:\n cursor.execute("""INSERT INTO bot VALUES (%s)""", (15,))\n",
2020-12-09T21:33:14