Python 使用Flask在MySQL数据库上插入新寄存器时出错
我正在寻求您的帮助,因为我在Python Flask上遇到以下错误:Python 使用Flask在MySQL数据库上插入新寄存器时出错,python,mysql,angular,database,flask,Python,Mysql,Angular,Database,Flask,我正在寻求您的帮助,因为我在Python Flask上遇到以下错误: pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Autoevaluacion', 'RT_Funcionarios', 'Repor
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Autoevaluacion', 'RT_Funcionarios', 'Reporteadores', 'Reporteadores_Gerentes', '' at line 1")
在Flask的帮助下,我在MySQL数据库中插入Angular的数据,我尝试插入字段名称、电子邮件、角色和foros,最后一个字段填充了数组元素,因此当我尝试保存数据时,会显示错误
这是我的python代码
@app.route('/insertarUsuario', methods = ["POST"])
def insertar_usuario():
conection = pymysql.connect('localhost', 'root','root', 'users')
data = request.json
print(data)
print(data['foros'])
cursor = conection.cursor()
sql_query ="INSERT INTO administrador_usuarios(nombre, email, rol, foros) VALUES ('" + str(data["nombre"]) + "','"+ str(data["email"])+"','"+str(data["rol"])+"', '"+ str(data["foros"])+"')"
cursor.execute(sql_query)
conection.commit()
response = "OK"
print("respuesta:",response)
return jsonify(response)
我想强调两点:
1-。这个数组将填充foros字段,它来自于您通过复选框选择的foros数量,因此如果我只选中一个,寄存器将被保存,但是如果我选中多个,它将崩溃
2-。我发现如果我替换
(data["foros"])
为了
它可以工作,所以我想可能是关于如何接收阵列的问题
你能帮我吗?。我对Flask有点陌生如果你正在注册,你应该担心。您有一个需要插入数据库的数据列表?如果正在注册,您应该担心。您有需要插入数据库的数据列表吗?
str("autoevaluacion" + "rt_funcionario")