'MySQL database not inserting data in Flask application

I have a flask app from which I insert data to the database from the /register page on my website. The website works normally on my laptop on the test flask server but when I transfer the application to my home server and upload it with the WSGI server the app doesn't insert data into the database. The database is the same on my laptop and the code is completely the same, but for some reason the database doesn't upload data when I run the website on the server. I know that the website is correctly connected to the SQL Database because I can still SELECT data from it, but cannot upload. Do you know what may be the problem?

This is my python code:

@app.route("/register", methods=["GET","POST"])
def register():
    try_again = False
    if request.method == "POST":
        name = request.form['name']
        username = request.form['user']
        log = mysql.connection.cursor() 
        log.execute("SELECT username FROM usersdb WHERE username='{}'".format(username))
        log = log.fetchall()
        if len(log) == 0:
            salt = ''.join(random.choice(alphabet) for i in range(16))
            pwd = (hashlib.sha1((salt+request.form['pass']).encode())).hexdigest()
            cur = mysql.connection.cursor() 
            cur.execute(("""INSERT INTO usersdb (name, username, pass, salt)
            VALUES ('{}', '{}', '{}', '{}')""").format(name, username, pwd, salt))
            session["user"] = username
            return redirect("/")
        else:
            try_again = True
    return render_template("register.html", try_again=try_again)
if __name__ == "__main__":
    app.run(debug = True)

Also when I manually insert the data it uploads twice!!! And it skips some autoincrement numbers on the ID column because it acts like it already used them when flask tried to upload the data the previous times.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source