Usucha Bootsarakam Usucha Bootsarakam - 1 month ago 9
Python Question

I can't delete data multiple in mysql from python

I made input 2 value row and num when input data so program throw Rollback not work if-else and thank for help

#!/usr/bin/python
import mysql.connector
conn = mysql.connector.connect(host="",user="",passwd="",db="")
cursor = conn.cursor()
try:
row = raw_input("InputNameRow : ")
num = int(input("InputNumber 1-10 : "))
if num <= 10:
sql1 = "SELECT * FROM dt WHERE '%s' = '%d' " %(row,num)
cursor.execute(sql1)
data = cursor.fetchall()
print(data[0])
sqlde = "DELETE FROM dt WHERE '%s' = '%d' " %(row,num)
cursor.execute(sqlde, (num))
print "DELETE SUCESS"
conn.commit()
else:
print "Data Empty"
except:
conn.rollback()
print "Input Error"

conn.close()

Answer

Try :

cursor.execute(sqlde)

instead of

cursor.execute(sqlde, (num))
Comments