0

The problem is this: When the command runs, it does not replace the data in the database.

I looked at countless pages but found no solution to the problem.

But it doesn't give an error.

Script:

@app.route('/profil', methods=['GET', 'POST'])
def profil():

    if 'loggedin' in session:
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute('SELECT * FROM users WHERE id = %s', (session['id'],))
        account = cursor.fetchone()

        if request.method == 'POST':
            file = request.files['file']
            filename = secure_filename(file.filename)

            path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(path)

            cursor.execute('UPDATE users SET file_name = %s WHERE id = %s', (filename,account['id'],))

            return filename

        return render_template('profil.html', account=account)

    return redirect(url_for('login'))```
oglosak234
  • 38
  • 1
  • 5

1 Answers1

1

When doing an UPDATE you need to commit explicitly with .commit:

cnx = mysql.connector.connect(...)
cursor = cnx.cursor()
cursor.execute('UPDATE .....')
cnx.commit()

https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-commit.html

You can autocommit with cnx.autocommit = True.

oglosak234
  • 38
  • 1
  • 5