CS Project Pages
CS Project Pages
JAGDISHPUR
AISSCE 2025
Teacher's Remark -
2
CERTIFICATE
This is to certify that the project report entitled,
Student Management System
is being
submitted to
Indorama Public School
Jagdishpur
in partial fulfillment of
AISSCE 2025
This is the original work carried out by our
Bonafide student,
Swapnil Agrahari
under my
guidance. The content embodied in this project
is
the genuine work done by the student.
3
SYNOPSIS
Project Title: Student Management System
Objective:
This code implements a console-based Student
Management System in Python to manage student data in a
MySQL database. It connects to the database, allowing an
admin to add, view, or delete student records, record
attendance, and assign marks. Students can log in to view
their attendance and marks. The system authenticates users
as either admins or students and provides role-based
permissions for different operations. It includes methods for
database connectivity, input validation, and safe connection
closure. The interface is menu-driven, allowing users to
interact with the system through simple prompts and
commands.
4
PROJECT SPECIFICATIONS
Function Description:
5
DATABASE USED:- student_management
Tables used:
Students:
Attendance:
Marks:
6
SOURCE CODE
7
import mysql.connector
from mysql.connector import Error
from datetime import date
class StudentManagementSystem:
def __init__(self):
# Initialize the database connection and user role
self.connection = self.create_connection()
self.current_user_role = None
self.current_student_id = None # Store the logged-in student ID
def create_connection(self):
# Create a connection to the MySQL database
try:
connection = mysql.connector.connect(
host='localhost',
user='root',
password='tiger',
database='student_management'
)
if connection.is_connected():
#print("Connected to the database.")
return connection
except Error as e:
print(f"Error: {e}")
return None
def check_connection(self):
# Check if the database connection is active; if not, attempt to reconnect
if self.connection is None or not self.connection.is_connected():
print("No connection to the database. Attempting to reconnect...")
self.connection = self.create_connection()
if self.connection is None:
print("Failed to reconnect to the database. Please try again later.")
return False
return True
def authenticate_user(self):
# User authentication method for admin and students
try:
while True:
print("\n--- User Authentication ---")
print("1. Admin Login")
print("2. Student Login")
print("3. Exit")
choice = input("Choose your role: ")
if choice == '1':
username = input("Enter admin username: ")
password = input("Enter admin password: ")
if username == "admin" and password == "admin123": # Simple authentication
self.current_user_role = "admin"
print("Admin logged in.") 8
return True
else:
print("Invalid admin credentials.")
else:
print("Invalid choice.")
except Exception as e:
print(f"Error during authentication: {e}")
def add_student(self, student_id, name, fname, dob, major, roll_no, class_code, pno, email):
if self.current_user_role != "admin":
print("Permission denied: Only admins can add students.")
return
if not self.check_connection():
return
try:
with self.connection.cursor() as cursor:
query = "INSERT INTO students (id, name, father_name, dob, major, roll_no, class_code, phone_no, email) VALUES (%s, %s, %s, %s,
%s, %s, %s, %s, %s)"
cursor.execute(query, (student_id, name, fname, dob, major, roll_no, class_code, pno, email))
self.connection.commit()
print(f"Student {name} added successfully.")
except Error as e:
print(f"Failed to add student: {e}")
def view_students(self):
if not self.check_connection():
return
try:
with self.connection.cursor() as cursor:
query = "SELECT * FROM students"
cursor.execute(query)
rows = cursor.fetchall()
if rows:
print("\n--- Students List ---")
for row in rows:
print(row)
else:
print("No student records found.")
except Error as e:
print(f"Failed to retrieve students: {e}") 9
if not self.check_connection():
return
try:
with self.connection.cursor() as cursor:
query = "INSERT INTO attendance (student_id, date, status, late_arrival) VALUES (%s, %s, %s ,%s)"
cursor.execute(query, (student_id, date.today(), status, late_arrival))
self.connection.commit()
print(f"Attendance recorded for student ID {student_id}: {status}.")
except Error as e:
print(f"Failed to record attendance: {e}")
def view_attendance(self):
if not self.check_connection():
return
try:
with self.connection.cursor() as cursor:
query = "SELECT * FROM attendance WHERE student_id = %s"
cursor.execute(query, (self.current_student_id,))
rows = cursor.fetchall()
if rows:
print(f"\n--- Attendance for Student ID {self.current_student_id} ---")
for row in rows:
print(row)
else:
print("No attendance records found.")
except Error as e: 10
print(f"Failed to retrieve attendance: {e}")
if not self.check_connection():
return
try:
with self.connection.cursor() as cursor:
query = "INSERT INTO marks (student_id, roll_no, class_code, subject, score) VALUES (%s, %s, %s, %s, %s)"
cursor.execute(query, (student_id, roll_no, class_code, subject, score))
self.connection.commit()
print(f"Marks added for student ID {student_id} in {subject}.")
except Error as e:
print(f"Failed to add marks: {e}")
def view_marks(self):
if not self.check_connection():
return
try:
with self.connection.cursor() as cursor:
query = "SELECT * FROM marks WHERE student_id = %s"
cursor.execute(query, (self.current_student_id,))
rows = cursor.fetchall()
if rows:
print(f"\n--- Marks for Student ID {self.current_student_id} ---")
for row in rows:
print(row)
else:
print("No marks records found.")
except Error as e:
print(f"Failed to retrieve marks: {e}")
def close_connection(self):
try:
if self.connection is not None and self.connection.is_connected():
self.connection.close()
print("MySQL connection is closed.")
except Error as e:
print(f"Error closing the connection: {e}")
if __name__ == "__main__":
sms = StudentManagementSystem()
while True:
if not sms.authenticate_user():
break # Exit the loop if authentication fails or user chooses to exit
while True: 11
if sms.current_user_role == "admin":
print("\n--- Admin Menu ---")
print("1. Add Student")
print("2. View Students")
print("3. Delete Student")
print("4. Record Attendance")
print("5. View Attendance")
print("6. Add Marks")
print("7. View Marks")
print("8. Exit")
if choice == '1':
student_id = int(input("Enter student ID: "))
name = input("Enter student name: ")
fname = input("Enter father's name: ")
dob = input("Enter student's dob (YYYY-MM-DD): ")
major = input("Enter student major: ")
roll_no = input("Enter student roll number: ")
class_code = input("Enter student class: ")
pno = int(input("Enter Phone number: "))
email = input("Enter email: ")
sms.add_student(student_id, name, fname, dob, major, roll_no, class_code, pno, email)
elif choice == '2':
sms.view_students() # View all students
elif choice == '3':
student_id = int(input("Enter student ID to delete: "))
sms.delete_student(student_id) # Delete a student
elif choice == '4':
student_id = int(input("Enter student ID for attendance: "))
status = input("Enter status (Present/Absent): ")
late_arrival = input("Is student arriving late? (Yes/No): ")
sms.record_attendance(student_id, status, late_arrival) # Record attendance
elif choice == '5':
sms.view_attendance() # View attendance records
elif choice == '6':
student_id = int(input("Enter student ID for marks: "))
subject = input("Enter subject name: ")
score = int(input("Enter score: "))
roll_no = input("Enter student roll number: ")
class_code = input("Enter student class: ")
sms.add_marks(student_id, subject, score, roll_no, class_code) # Add marks
elif choice == '7':
sms.view_marks() # View marks records
elif choice == '8':
print("Exiting admin menu...")
break # Exit admin menu
else:
print("Invalid choice.")
if choice == '1':
sms.view_attendance() # View attendance records
elif choice == '2':
sms.view_marks() # View marks records
elif choice == '3':
print("Exiting student menu...")
break # Exit student menu
else:
print("Invalid choice.")
sms.close_connection() # Ensure the database connection is closed on exit
14
OUTPUT
15
Student Interface:
16
BIBLIOGRAPHY
•
Computer Science with Python
by Sumita Arora, for class 11th
and 12th
• W3School, www.w3schools.com
17