SOURCE CODE
import mysql.connector as con
# To search students from student details table.
def search_student():
print("***************** STUDENT DETAILS ***********************")
k = input("Enter name to search student Name: ")
d = con.connect(host="localhost", user="root", password="root",
database="STUDENT")
c = d.cursor()
c.execute("SELECT * FROM STUDENT_DETAILS WHERE NAME LIKE '%{}
%'".format(k))
a = c.fetchall()
if len(a) >= 1:
for i in a:
print("Admission no:", i[0])
print("Name is:", i[1])
print("Sex:", i[2])
print("Class:", i[3])
print("Sec:", i[4])
print("Phone number is:", i[5])
print("Email_id:", i[6])
print("Stream is:", i[7])
print("----------------------------------------------------")
else:
print("Student Details Not Found")
d.commit()
# To update details of students from student details table.
def update_details():
d = con.connect(host="localhost", user="root", password="root",
database="STUDENT_MANAGEMENT_SYSTEM")
c = d.cursor()
print("1. Update Name")
print("2. Update Gender")
print("3. Update Class")
print("4. Update Section")
print("5. Update Phone no.")
print("6. Update E-mail id")
print("7. Update Stream")
opt = int(input("Enter your choice to update: "))
if opt == 1:
print("---------------------------------------------------")
print("You are inside updating name.")
q = input("Enter ADMISSION_NUMBER whose data you want to update: ")
l = input("Enter your updated name: ")
c.execute("UPDATE STUDENT_DETAILS SET NAME='{}' WHERE
ADMISSION_NUMBER={}".format(l, q))
d.commit()
elif opt == 2:
print("---------------------------------------------------")
print("You are inside updating Gender.")
p = input("Enter name whose data you want to update: ")
l = input("Enter your updated Gender: ")
c.execute("UPDATE STUDENT_DETAILS SET SEX='{}' WHERE
NAME='{}'".format(l, p))
d.commit()
elif opt == 3:
print("---------------------------------------------------")
print("You are inside updating class.")
m = input("Enter name whose data you want to update: ")
n = input("Enter your updated class: ")
c.execute("UPDATE STUDENT_DETAILS SET CLASS={} WHERE
NAME='{}'".format(n, m))
d.commit()
elif opt == 4:
print("---------------------------------------------------")
print("You are inside updating section.")
y = input("Enter name whose data you want to update: ")
e = input("Enter your updated section: ")
c.execute("UPDATE STUDENT_DETAILS SET SEC='{}' WHERE
NAME='{}'".format(e, y))
d.commit()
elif opt == 5:
print("---------------------------------------------------")
print("You are inside updating phone number.")
h = input("Enter name whose data you want to update: ")
r = input("Enter your updated phone number: ")
c.execute("UPDATE STUDENT_DETAILS SET PHONE_NUMBER={} WHERE
NAME='{}'".format(r, h))
d.commit()
elif opt == 6:
print("---------------------------------------------------")
print("You are inside updating email_id.")
j = input("Enter name whose data you want to update: ")
k = input("Enter your updated email_id: ")
c.execute("UPDATE STUDENT_DETAILS SET EMAIL_ID='{}' WHERE
NAME='{}'".format(k, j))
d.commit()
elif opt == 7:
print("---------------------------------------------------")
print("You are inside updating stream.")
f = input("Enter name whose data you want to update: ")
z = input("Enter your updated stream: ")
c.execute("UPDATE STUDENT_DETAILS SET STREAM='{}' WHERE
NAME='{}'".format(z, f))
d.commit()
else:
print("Invalid option. Please try again.")
# To display the marks of students from student details table.
def view_marks():
print("******************* VIEW STUDENT DETAILS ******************")
k = input("Enter name to view student details: ")
d = con.connect(host="localhost", user="root", password="root",
database="STUDENT_MANAGEMENT_SYSTEM")
c = d.cursor()
c.execute("SELECT * FROM STUDENT_DETAILS WHERE NAME LIKE '%{}
%'".format(k))
s = c.fetchall
for i in s:
print("MARKS:", i[8])
print("-----------------------------------------------------")
d.commit()
# To insert details to student details table
def add_student():
print(".................. ADD STUDENT DETAILS......................")
n = input("Enter student name: ")
a = int(input("Enter student admission number: "))
r = input("Enter gender of student: ")
i = int(input("Enter class of student: "))
p = input("Enter student section: ")
t = int(input("Enter student phone number: "))
w = input("Enter student stream: ")
u = input("Enter your mail id: ")
m = int(input("Enter your marks: "))
d = con.connect(host="localhost", user="root", password="root",
database="STUDENT_MANAGEMENT_SYSTEM")
c = d.cursor()
sq = "INSERT INTO STUDENT_DETAILS VALUES({}, '{}', '{}', {}, '{}', {}, '{}', '{}',
{})".format(a, n, r, i, p, t, u, w, m)
c.execute(sq)
d.commit()
print("Student data added successfully")
# To delete items from student details table
def delete_student():
print("******************** DELETE STUDENT DETAILS
*******************")
k = input("Enter name to DELETE student details: ")
d = con.connect(host="localhost", user="root", password="root",
database="STUDENT_MANAGEMENT_SYSTEM")
c = d.cursor()
c.execute("DELETE FROM STUDENT_DETAILS WHERE NAME='{}'".format(k))
print(".........Data deleted successfully..........")
d.commit()
def admin():
while True:
print("*************** WELCOME TO STUDENT MANAGEMENT
*****************")
print("----------------------------------------------------------")
print("1. Search student details")
print("2. Update student details")
print("3. View student details")
print("4. Add student details")
print("5. Delete student details")
print("6. Exit")
ch = int(input("Your choice: "))
if ch == 1:
search_student()
elif ch == 2:
update_details()
elif ch == 3:
view_marks()
elif ch == 4:
add_student()
elif ch == 5:
delete_student()
elif ch == 6:
break
else:
print("Invalid input")
def user():
while True:
print("*************** WELCOME TO STUDENT MANAGEMENT
**************")
print("1. Search your Details")
print("2. View Details")
print("3. Exit")
ch = int(input("What is your choice: "))
if ch == 1:
search()
elif ch == 2:
view_marks()
elif ch == 3:
break
else:
print("Invalid input")
# To search students from student details table.
def search():
print("***************** STUDENT DETAILS ***********************")
k = input("Enter name to search student details: ")
d = con.connect(host="localhost", user="root", password="root",
database="STUDENT_MANAGEMENT_SYSTEM")
c = d.cursor()
c.execute("SELECT * FROM STUDENT_DETAILS WHERE NAME LIKE '%{}
%'".format(k))
a = c.fetchall()
if len(a) >= 1:
for i in a:
print("Admission no:", i[0])
print("Name is:", i[1])
print("Sex:", i[2])
print("Class:", i[3])
print("Sec:", i[4])
print("Phone number is:", i[5])
print("Email_id:", i[6])
print("Stream is:", i[7])
print("----------------------------------------------------")
else:
print("Student Details Not Found")
d.commit()
while True:
print("************** WELCOME TO STUDENT MANAGEMENT
*****************")
print("1. Admin")
print("2. User")
print("3. Exit")
ch = int(input("Login through: "))
if ch == 1:
admin()
elif ch == 2:
user()
elif ch == 3:
break
else:
print("Invalid input")
OUTPUT
#USER AND ADMIN PANEL
#SEARCH STUDENT
#UPDATE NAME
#UPDATE GENDER
#UPDATE CLASS
#UPDATE SECTION
#STREAM
#View Mark of student
#Add student Details