Help with the syntax, you need to pour 3 variables into the database, how to list them correctly? This code does not work.

insert23 = ("""INSERT INTO app (userid, req1, type) values (%s, %s, %s)""" % id % req1 % type) cur.execute(insert23) conn.commit() 
  • insert23 = "INSERT INTO app (userid, req1, type) values (%s, %s, %s)" % (id, req1, type) - Pavel
  • Thanks, it helped - Denis

2 answers 2

You can also try, " do not use string formatting to access the database. Use parameterized queries instead. "

 cur.execute("INSERT INTO app (userid, req1, type) values (%s, %s, %s)", (id, req1, type)) 

or

 insert23 = ("""INSERT INTO app (userid, req1, type) values (%s, %s, %s)""") cur.execute(insert23, (id, req1, type)) 
     insert23 = "INSERT INTO app (userid, req1, type) values (%s, %s, %s)" % (id, req1, type) 

    Pavel helped, decided, thanks