I want to update mysql table in a function,and the updated value is realated to the two argument the function takes
I am a freshman and am doing a python project in which I have a table in mysql to store some data .and there is a function in my projrct which take 2 argument:user and consumption. I want to update a value in my table,and the updated value equel to the previous value plus consumption(an argument taken),I need to creat a sql:
UPDATE consumption_record SET
total_consumption=total_consumption+consumption WHERE name=user
but there is two syntax in this sql, I want to konw how can I change my code to meet my need?
def increase_consumption(self,user,consumption):
mycursor.execute("SELECT total_consumption FROM biao WHERE username="+"'"+user+"'")
ori_con=int(mycursor.fetchall()[0][0])
updated_con=str(consumption+ori_con)
sql="UPDATE biao SET total_consumption="+updated_con+"WHERE username="+"\'"+user+"\'"
mycursor.execute(sql)
mycursor.commit()