Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

AAKKAM

SESSION 7
BACKEND CONNECTION FOR DESIGN PAGE (INSERTING ALL
DATA)

TODAY’S QUOTES

LANGUAGE IS THE ROAD


MAP OF A CULTURE.
IT TELLS YOU WHERE
ITS PEOPLE COME FROM
AND
WHERE THEY ARE GOING

1
AAKKAM

import os
from flask import Flask,render_template,request,redirect
from werkzeug.utils import secure_filename
from flaskext.mysql import MySQL
app=Flask(__name__)
mysql=MySQL()

app.config["MYSQL_DATABASE_USER"]='root'
app.config["MYSQL_DATABASE_PASSWORD"]=''
app.config["MYSQL_DATABASE_DB"]='attendence'
app.config["MYSQL_DATABASE_HOST"]='localhost'
mysql.init_app(app)

@app.route("/attendence")
def attendence():
return render_template("attendence.html")

@app.route("/adminlogin",methods=['POST','GET'])
def adminlogin():
if request.method=='POST':
username=request.form['username']
password=request.form['pass']
if username=='admin' and password=='admin':

2
AAKKAM

return redirect('adminhome')
else:
error='invalid'
else:
return render_template("adminlogin.html")

@app.route("/adminhome")
def adminhome():
return render_template("adminhome.html")

@app.route("/adminviewstaff")
def adminviewstaff():
return render_template("adminviewstaff.html")

@app.route("/adminviewstudent")
def adminviewstudent():
return render_template("adminviewstudent.html")

@app.route("/stafflogin",methods=['POST','GET'])
def stafflogin():
if request.method=='POST':
username=request.form['username']
password=request.form['pass']
conn=mysql.connect()
cur=conn.cursor()

3
AAKKAM

cur.execute("SELECT * FROM `staff` WHERE `username`='"+username+"'


and `password`='"+password+"'")
data=cur.fetchone()
if data[5]==username and data[6]==password:
return redirect('staffhome')
else:
error='invalid'
else:
return render_template("stafflogin.html")

@app.route("/staffregister",methods=['POST','GET'])
def staffregister():
if request.method=='POST':
title=request.form['title']
name=request.form['name']
email=request.form['email']
phno=request.form['phno']
username=request.form['username']
password=request.form['password']
gender=request.form['gender']
conn=mysql.connect()
cur=conn.cursor()
cur.execute("INSERT INTO `staff`(`title`, `name`, `email`, `phno`, `username
`, `password`, `gender`) VALUES (%s,%s,%s,%s,%s,%s,%s)",(title,name,email,ph
no,username,password,gender))
conn.commit()

4
AAKKAM

return redirect('stafflogin')
else:
return render_template("staffregister.html")

@app.route("/staffhome")
def staffhome():
return render_template("staffhome.html")

@app.route("/staffaddstu",methods=['POST','GET'])
def staffaddstu():
if request.method=='POST':
studentname=request.form['studentname']
rollno=request.form['rollno']
gender=request.form['gender']
phno=request.form['phno']
email=request.form['email']
fathername=request.form['fathername']
address=request.form['address']
dept=request.form['dept']
APP_PATH_ROUTE=os.path.dirname(os.path.abspath(__file__))
target=os.path.join(APP_PATH_ROUTE,'uploads')
UPLOAD_FOLDER='{}/static/uploads/'.format(APP_PATH_ROUTE)
app.config['UPLOAD_FOLDER']=UPLOAD_FOLDER
files=request.files['files']
f=os.path.join(UPLOAD_FOLDER,files.filename)

5
AAKKAM

files.save(f)
filename=secure_filename(files.filename)
conn=mysql.connect()
cur=conn.cursor()
cur.execute("INSERT INTO `student`(`studentname`, `rollno`, `gender`, `phn
o`, `email`, `fathername`, `address`, `dept`, `image`) VALUES (%s,%s,%s,%s,%s,
%s,%s,%s,%s)",(studentname,rollno,gender,phno,email,fathername,address,dept,fi
lename))
conn.commit()
return redirect('staffviewstu')
else:
return render_template("staffaddstu.html")

@app.route("/staffviewstu")
def staffviewstu():
return render_template("staffviewstu.html")

@app.route("/studentlogin",methods=['POST','GET'])
def studentlogin():
if request.method=='POST':
rollno=request.form['rollno']
conn=mysql.connect()
cur=conn.cursor()
cur.execute("SELECT * FROM `student` WHERE `rollno`='"+rollno+"'")
data=cur.fetchone()

6
AAKKAM

if data[2]==rollno:
return redirect('studenthome')
else:
error='invalid'
else:
return render_template("studentlogin.html")

@app.route("/studenthome")
def studenthome():
return render_template("studenthome.html")

@app.route("/studentprofile")
def studentprofile():
return render_template("studentprofile.html")

@app.route("/studentviewatt")
def studentviewatt():
return render_template("studentviewatt.html")

if(__name__=="__main__"):
app.run(debug=True)

You might also like