IP Codes
IP Codes
Host: localhost
User: root
Password: Gau2002
Database: MySQL
Table: Student
Table: Emp
Table: Fee
Table:Exam
Python Code
import os import platform
import mysql.connector
def selection():
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql') cursor = db.cursor()
print('-----------------------------------\WELCOME TO SCHOOL MANAGEMENT SYSTEM\-----------------------
------------')
print("1.STUDENT MANAGEMENT")
print("2.EMPLOYEE MANAGEMENT") print("3.FEE
MANAGEMENT")
print("4.EXAM MANAGEMENT")
def insert1():
sname=input("Enter Student Name : ")
admno=int(input("Enter Admission No : "))
dob=input("Enter Date of Birth(yyyy-mm-dd): ")
cls=input("Enter class for admission: ") cty=input("Enter
City : ")
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
for c in results:
sname = c[0] admno=
c[1] dob=c[2]
cls=c[3] cty=c[4]
except: print ("Error:
unable to fetch data")
print()
tempst=int(input("Enter Admission No : "))
temp=input("Enter new class : ") try:
sql = "Update student set cls=%s where admno='%d'" % (temp,tempst)
cursor.execute(sql) db.commit() except Exception as e:
print (e)
db.close() def
delete1(): try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql') cursor = db.cursor() sql =
"SELECT * FROM student"
cursor.execute(sql)
results = cursor.fetchall()
for c in results: sname =
c[0] admno= c[1]
dob=c[2] cls=c[3]
cty=c[4] except:
print ("Error: unable to fetch data")
job=c[2]
hiredate=c[3]
print ("(empno=%d,ename=%s,job=%s,hiredate=%s)" % (empno,ename,job,hiredate)) except:
print ("Error: unable to fetch data")
db.close() def update2(): try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor() sql =
"SELECT * FROM emp"
cursor.execute(sql) results =
cursor.fetchall() for c in results:
ename = c[0] empno= c[1]
job=c[2] hiredate=c[3] except:
print ("Error: unable to fetch data")
print()
tempst=int(input("Enter Employee No : "))
temp=input("Enter new designation : ")
try:
sql = "Update emp set job=%s where empno='%d'" % (temp,tempst)
cursor.execute(sql) db.commit() except Exception as e:
print (e) db.close() def delete2(): try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor() sql =
"SELECT * FROM emp"
cursor.execute(sql) results =
cursor.fetchall() for c in
results: ename = c[0]
empno= c[1] job=c[2]
hiredate=c[3] except:
print ("Error: unable to fetch data")
db.commit()
except Exception as e:
print (e) db.close()
def insert3():
admno=int(input("Enter adm no: ")) fee=float(input("Enter
fee amount : ")) month=input("Enter Month: ")
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql') cursor = db.cursor()
sql="INSERT INTO fee(admno,fee,month) VALUES ( '%d','%d','%s')"%(admno,fee,month) try:
cursor.execute(sql)
db.commit() except:
db.rollback()
db.close()
db.commit()
except Exception as e:
print (e) db.close()
def delete3(): try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor() sql =
"SELECT * FROM fee"
cursor.execute(sql) results =
cursor.fetchall() for c in results:
admno= c[0] fee=c[1]
month=c[2] except:
print ("Error: unable to fetch data")
temp=int(input("Enter adm no to be deleted : ")) try:
sql = "delete from student where admno='%d'" % (temp)
ans=input("Are you sure you want to delete the record(y/n) : ")
if ans=='y' or ans=='Y': cursor.execute(sql)
db.commit() except Exception as e: print (e)
db.close() def insert4():
sname=input("Enter Student Name : ")
admno=int(input("Enter Admission No : "))
per=float(input("Enter percentage : ")) res=input("Enter
result: ")
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql="INSERT INTO exam(sname,admno,per,res) VALUES ( '%s'
,'%d','%s','%s')"%(sname,admno,per,res) try:
cursor.execute(sql)
db.commit() except:
db.rollback()
db.close() def
display4(): try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql') cursor = db.cursor() sql =
"SELECT * FROM exam" cursor.execute(sql) results =
cursor.fetchall() for c in results:
sname = c[0]
admno= c[1]
dob=c[2] cls=c[3]
cty=c[4]
print ("(sname,admno,per,res)"%(sname,admno,per,res) )
except:
print ("Error: unable to fetch data")
db.close()
INSERT DETAILS
UPDATE DETAILS
Ln:34 Col: 4
DELETE DETAILS