如何在pythonflas中编辑从数据库中获取的数据

2024-09-29 19:27:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我在编辑从DB获取的值时遇到了问题。 遇到以下错误:

mysql_exceptions.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 '%s' at line 1")

结果显示如下

Display Results

例如,当单击“编辑配置文件”时,将正确获取以下详细信息

Web Form GUI

在编辑详细信息并单击提交时遇到上述错误

使用下面的代码编辑结果

@app.route('/Update', methods=['GET', 'POST'])
def Update():
        CR_ID = request.args.get('CR_ID')
        cur = mysql.connection.cursor()
        result = cur.execute("""SELECT CR_ID, name, email, CRType from users where CR_ID = %s""",CR_ID)
     #   result = cur.execute("Update table users set name=?, email=?, CRType=? where CR_ID = %s", CR_ID)
        RV = cur.fetchall()
        user = RV[0]
        cur.close()
        return render_template('Update.html',user=user)

使用以下代码更新记录:

@app.route('/UpdateData', methods=['GET', 'POST'])
def UpdateData():
        name = request.args.get('name')
        email = request.args.get('email')
        CRType = request.args.get('CRType')
        cur = mysql.connection.cursor()
        result = cur.execute("""Update table users set name=?, email=?, CRType=? where CR_ID = ?""")
        mysql.connection.commit()
        cur.close()
        return index()

Tags: nameid编辑executegetemailrequestmysql

热门问题