-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
27 lines (27 loc) · 1.17 KB
/
Copy pathsql.py
File metadata and controls
27 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import mysql.connector
from flask import Flask, request, render_template
from flaskext.mysql import MySQL
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = '1234'
app.config['MYSQL_DATABASE_DB'] = 'db'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql = MySQL(app)
cursor = mysql.connect().cursor()
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
user_details = request.form
firstName = user_details['firstName']
lastName = user_details['lastName']
birthday = user_details['birthday']
address = user_details['address']
numChild = user_details['numChild']
income = user_details['income']
housing = user_details['housing']
restrictions = user_details['restrictions']
cursor.execute('INSERT INTO users(firstName, lastName, birthday, address, numChild, income, housing, restrictions) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', (firstName, lastName, birthday, address, numChild, income, housing, restrictions))
mysql.connect().commit()
cursor.close()
return 'success'
return 'failed'