hi, Im writing a program at the moment(below) that interacts with a MySQL database and im having a problem. As you can see ive written a query that will look for products in the products table that corresponds to the barcode that the user has inputted. If the barcode that is inputted by the user is found in the products table, I want to increase the 'amount' field by 1 in the stocks table where the product that corresponds to the barcode inputted, is the same as the product in the stocks table. as you can see ive tried to assign a variable to the for loop to try and get it to work that way but its not working. does anyone have any idea of how to do it. thanks.
import MySQLdb
def look_up_product():
db = MySQLdb.connect(host='localhost', user = 'root', passwd='$$', db='fillmyfridge')
cursor = db.cursor (MySQLdb.cursors.DictCursor)
user_input=raw_input('please enter the product barcode that you wish to checkin to the fridge: \n')
if cursor.execute("""select * from products where product = %s""", (user_input)):
db.commit()
result_set = cursor.fetchall ()
#i want here to assign a variable to this for loop and the line below = for product in result_set:
print "%s" % (row["product"])
cursor.execute('update stocks set amount = amount + 1 where product = %s', (#here i want the result of the for loop))
db.commit()
else:
print 'no not in products table'
thanks a million. lincoln