1

I am making a user management system application, a user can have more than one admin, so one of my columns in mysql is in json format, but how do I update this column, how do I add it? When I try to update the request.form with the data I get from the user, I get the error "400 Bad Request: The browser (or proxy) sent a request that this server could not understand".

@Admin.route('/update', methods = ['POST' , 'GET'])
def update():
        # GET : The most common method. A GET message is send, and the server returns data
        # POST : Used to send HTML form data to the server. The data received by the POST method is not cached by the server.
    if request.method == 'POST':
        # get data from user
        id = request.form['userid']
        name = request.form['name']
        email = request.form['email']
        role = request.form['role']
        managerid = request.form['managerid']
        managedBY = request.form['managedBY']

        try:
            connection = create_connection()
            cursor = connection.cursor()
            # After connecting to the database, the following query has been performed to update the data with the data from the user
            sql = "UPDATE users SET name= %s, email= %s,  role=%s, managerid=%s, managedBY=%s WHERE userid= %s"
            values = (name , email,  role, managerid, managedBY, id)
            cursor.execute(sql , values)
            connection.commit()
            flash("Data Updated Succesfully")
        except pymysql.connect.Error as err:
            print('hata: ', err)

        finally:
            connection.close()
            print('database bağlantısı kapandı.')

        return redirect(url_for('Admin.Index'))[database column](https://i.stack.imgur.com/19IM8.png)```


Since a user has more than one manager, I had to use json data in mysql, but I cannot connect this json column with form operations in html. My goal is to reach this column and make changes in it (update, insert, delete)

1 Answers1

-1

Its recommended that you follow Database best practices, in this case a One-To-Many Relationship one-to-many is recommended as a User is going to have more than one Managers. This will make your application robust as well as remove redundancy.