-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (52 loc) · 1.86 KB
/
app.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask, render_template, request, redirect, url_for
import mysql.connector
app = Flask(__name__)
db = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="employee_db"
)
cursor = db.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
mobile_number VARCHAR(20) NOT NULL,
email VARCHAR(255) NOT NULL,
birth_date DATE NOT NULL,
special_interests TEXT,
learning_institutions TEXT
)
""")
@app.route('/')
def index():
return render_template('index.html')
@app.route('/new_form')
def new_form():
return render_template('new_form.html')
@app.route('/submit_form', methods=['POST'])
def submit_form():
if request.method == 'POST':
name = request.form['name']
address = request.form['address']
mobile_number = request.form['mobile_number']
email = request.form['email']
birth_date = request.form['birth_date']
special_interests = request.form['special_interests']
learning_institutions = request.form['learning_institutions']
cursor = db.cursor()
query = "INSERT INTO employees (name, address, mobile_number, email, birth_date, special_interests, learning_institutions) VALUES (%s, %s, %s, %s, %s, %s, %s)"
values = (name, address, mobile_number, email, birth_date, special_interests, learning_institutions)
cursor.execute(query, values)
db.commit()
return redirect(url_for('index'))
@app.route('/form_lists')
def form_lists():
cursor = db.cursor()
cursor.execute("SELECT * FROM employees")
employees = cursor.fetchall()
return render_template('form_lists.html', employees=employees)
if __name__ == '__main__':
app.run(debug=True)