I am trying to insert some values into my table. The code is:
import MySQLdb
db=MySQLdb.connect(host="localhost",user="user_name", passwd="",db="name_of_db", port=3306)
cursor=db.cursor()
readcount=52
sql="Insert into pressure_image(idItem, pressure_val, image_loc, array_time, Time_Stamp) values ('%d', 260, 'a.jpg', 'aray', 14-11-2000)"
try:
cursor.execute(sql, (readcount))
db.commit()
except:
print "No value inserted"
db.rollback()
The problem is when I try the insertion command like:
sql="Insert into pressure_image(idItem, pressure_val, image_loc, array_time, Time_Stamp) values (30, 260, 'a.jpg', 'aray', 14-11-2000)" the values are inserted in the table correctly but when I try the command as given in the code no values are inserted. So essentially, constants work but variables do not.
How do I insert variables into the table?