-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddEmp.py
58 lines (44 loc) · 1.38 KB
/
AddEmp.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
from flask import Flask
from flask import render_template, request
from pymysql import connections
import os
app = Flask(__name__)
DBHOST = os.environ.get("DBHOST")
DBPORT = os.environ.get("DBPORT")
DBPORT = int(DBPORT)
DBUSER = os.environ.get("DBUSER")
DBPWD = os.environ.get("DBPWD")
DATABASE = os.environ.get("DATABASE")
db_conn = connections.Connection(
host=DBHOST,
port=DBPORT,
user=DBUSER,
password=DBPWD,
db=DATABASE
)
output = {}
@app.route("/", methods=['GET', 'POST'])
def home():
return render_template('AddEmp.html')
@app.route("/AddEmp", methods=['POST'])
def updatedatabase():
emp_id = request.form['emp_id']
first_name = request.form['first_name']
last_name = request.form['last_name']
pri_skill = request.form['pri_skill']
location = request.form['location']
# image_file = request.form['image_file']
insert_sql = "INSERT INTO Employee VALUES (%s, %s, %s, %s, %s)"
cursor = db_conn.cursor()
try:
cursor.execute(insert_sql,(emp_id, first_name, last_name, pri_skill, location))
db_conn.commit()
emp_name = "" + first_name + " " + last_name
return render_template('AddEmpOutput.html', name=emp_name)
except Exception as e:
output["message"] = e
return output
finally:
cursor.close()
if __name__ == '__main__':
app.run(host='0.0.0.0',port=80,debug=True)