Tuesday 15 February 2011

python - MySQL not updating after calling connection.commit() with Flask (WORKING) -



python - MySQL not updating after calling connection.commit() with Flask (WORKING) -

i'm using flask build simple web app whatever reason conn.commit() not committing info database. know because when manually add together database info doesn't alter id section increases each time test (because using auto increment). current table has id 1, username test, password test , next entry inserted manually (after trying utilize application) id 5, username blah, password blah. there specific reason commit isn't working?

edit: had alter cursor = mysql.connect().cursor() conn.cursor()

@app.route('/add_data/') def add_tv_to_database(): conn = mysql.connect() cursor = mysql.connect().cursor() cursor.execute("insert _accounts values (null, 'test','test')") conn.commit() homecoming render_template('index.html')

in 4th line of code, alter cursor = mysql.connect().cursor() cursor = conn.cursor(). ensure cursor uses existing connection database (from previous line of code), instead of creating new mysql connection.

python html mysql flask

No comments:

Post a Comment