Error in sql-insert command when passing variable as parameter (python 3)

1

I am trying to pass my "table" variable to the mysql command, however it is returning an error (from sql) during execution. What am I missing?

Here I created the variable table

table = input ('Table name:')

while(tabela not in tabelasCadastradas):
    tabela = input('Tabela não cadastrada. Digite novamente:'.upper())
print(('Menu -> 1- Adicionar questão').upper())
opcaoMenu = input('')
while(opcaoMenu != '1'):
    opcaoMenu = ('Opção inválida. Digite novamente: '.upper())
tema = input('Tema: '.upper())
enunciado = input('Enunciado: '.upper())

Here is giving error

crawler.execute('INSERT INTO "%s" (id, tema, enunciado) VALUES (id, "%s", "%s")'%(tabela, tema, enunciado))

conn.close ()

    
asked by anonymous 28.09.2017 / 21:53

1 answer

-1

Solved with: crawler.execute('INSERT INTO {} VALUES (id, \'{}\', \'{}\')'.format(tabela, tema, enunciado))

    
29.09.2017 / 17:29