1from flask import Flask, render_template, request
2from flask_mysqldb import MySQL
3app = Flask(__name__)
4
5
6app.config['MYSQL_HOST'] = 'localhost'
7app.config['MYSQL_USER'] = 'root'
8app.config['MYSQL_PASSWORD'] = 'root'
9app.config['MYSQL_DB'] = 'MyDB'
10
11mysql = MySQL(app)
12
13
14@app.route('/', methods=['GET', 'POST'])
15def index():
16 if request.method == "POST":
17 details = request.form
18 firstName = details['fname']
19 lastName = details['lname']
20 cur = mysql.connection.cursor()
21 cur.execute("INSERT INTO MyUsers(firstName, lastName) VALUES (%s, %s)", (firstName, lastName))
22 mysql.connection.commit()
23 cur.close()
24 return 'success'
25 return render_template('index.html')
26
27
28if __name__ == '__main__':
29 app.run()
30
1from flask import Flask, render_template, request
2from flask_mysqldb import MySQL
3app = Flask(__name__)
4
5
6app.config['MYSQL_HOST'] = 'localhost'
7app.config['MYSQL_USER'] = 'root'
8app.config['MYSQL_PASSWORD'] = 'root'
9app.config['MYSQL_DB'] = 'MyDB'
10
11mysql = MySQL(app)
12
13
14@app.route('/', methods=['GET', 'POST'])
15def index():
16 if request.method == "POST":
17 details = request.form
18 firstName = details['fname']
19 lastName = details['lname']
20 cur = mysql.connection.cursor()
21 cur.execute("INSERT INTO MyUsers(firstName, lastName) VALUES (%s, %s)", (firstName, lastName))
22 mysql.connection.commit()
23 cur.close()
24 return 'success'
25 return render_template('index.html')
26
27
28if __name__ == '__main__':
29 app.run()