-1

Hi when I update data with sql, I get a string error. Please help me.

This is my error:

TypeError: not enough arguments for format stringimport pymysql.connect string error

My code is as follows:

db = mysql.connector.connect(user='root', password='1234', host='localhost', database='sosyalbe')
cursor = db.cursor()
cursor.execute("SELECT * FROM siparisler WHERE siparis_durum ='İptal'")

order = cursor.fetchone()
id = order[0]

dss = 10
cursor.execute("UPDATE siparisler SET urun_baslangic = '%s' WHERE order_id ='%s'" %dss % id)  #errror

cursor.execute("UPDATE siparisler SET urun_baslangic = (?) WHERE id = (?)" (dss, id))   #ERROR

please help !

Siong Thye Goh
  • 3,228
  • 10
  • 18
  • 28
omer
  • 1
  • 2
    Possible duplicate of [Python TypeError: not enough arguments for format string](https://stackoverflow.com/questions/11146190/python-typeerror-not-enough-arguments-for-format-string) – M. Spiller Jul 05 '19 at 19:39
  • i read this topic but it is not working – omer Jul 05 '19 at 19:44

1 Answers1

0

You're missing a comma between the string and tuple of arguments. Also, note that the %ss should not be surrounded with quotes, as they are not string literals:

cursor.execute("UPDATE siparisler SET urun_baslangic = %s WHERE order_id = %s", (dss, id))
Mureinik
  • 252,575
  • 45
  • 248
  • 283