我已经研究了这个问题,我知道出了什么问题,只是我不知道如何重新格式化"%s",对不起,我是python的新手。
@app.route("/edit_camera", methods = ["GET", "POST"])
def editcamera():
camera_id = request.args.get('id')# get the id parameter value
connection=create_connection()
if request.method =="POST":
get = request.form
Company = get["Company"]
Model = get["Model"]
PurchaseDate = get["PurchaseDate"]
Condition = get["Condition"]
KitLens = get["KitLens"]
PurchasePrice = get["PurchasePrice"]
#picture=
with connection.cursor() as cursor:
# Update record
update_sql = "UPDATE tblcameras SET tblcameras.Company = %s,tblcameras.Model=%s,tblcameras.PurchaseDate=%s,tblcameras.Condition=%s,tblcameras.KitLens=%s,tblcameras.PurchasePrice=%s WHERE cameras.CameraID = %s"
values=(Company,Model,camera_id)
cursor.execute(update_sql,(values))
#save or commit values in dbase
connection.commit()
cursor.close()
return redirect("/cameras")
return render_template("camera.html", title ="Editing New camera")
请尝试一下,
update_sql = "UPDATE tblcameras SET tblcameras.Company = '%s',tblcameras.Model='%s',tblcameras.PurchaseDate='%s',tblcameras.Condition='%s',tblcameras.KitLens='%s',tblcameras.PurchasePrice='%s' WHERE cameras.CameraID = '%s'"
values=(Company,Model,PurchaseDate,Condition,KitLens,PurchasePrice,camera_id)
cursor.execute(update_sql,(values))