connection = request.form.get('connection_type_id')
tariff = request.form.get('tariff_id')
house = request.form.get('house_type_id')
status = 1
mySql_insert_query = "INSERT INTO tbl_consumer(consumer_no, connection_type_id, tariff_id, house_type_id, status) VALUES (%s,%s,%s,%s,%s)"
cursor = connection.cursor()
result = cursor.execute(mySql_insert_query,(consumer, connection, tariff, house, status))
connection.commit()
print("Record inserted successfully into Laptop table")
cursor.close()
return redirect(url_for('admin_add_consumer'))
答案 0 :(得分:0)
connection = request.form.get('connection_type_id')
应该是connection_type_id = ....? request.form
默认为ImmutableMultiDict
,包含表单数据,您的连接变量设置为名称为connection_type_id的表单元素,这就是为什么会出错的原因。我假设连接是全局空间中的mysql连接对象。
请更改为connection_type_id = request.form.get('connection_type_id')
及其引用。