School Management System with PHP & MySQL | WD

School Management Systems (SMS) is a web application that commonly used in schools to manage teachers, students, classes, subjects, sections, students attendance etc.
So if you’re a PHP developer and wants to develop School Management System with PHP then you’re here at right place. In our previous tutorial you have learned how to develop online voting system with PHP and MYSQL. In this tutorial you will learn how to develop a School Management System with PHP and MySQL.
We will cover this tutorial in easy steps to develop live demo of school management systems to cover some major functionalities like manage teachers, students, classes, subjects, sections, students attendance etc. This is a very simple school management systems for learning purpose and can be enhanced according to requirement to develop a perfect advance level system. The download link is at the end of tutorial to download complete project with database tables.

Also, read:
So let’s start implementing School Management System with PHP and MySQL. Before we begin, take a look on files structure for this example.
index.php
School.php: A class to hold school methods.
dashboard.php
students.php
teacher.php
classes.php
subjects.php
sections.php
attendance.php
Step1: Create MySQL Database Table
First we will MySQL database tables sms_user, sms_teacher, sms_students, sms_classes, sms_subjects, sms_section and sms_attendance. All the tables structure and data is available in project download zip file.
Step2: Create User Login
In index.php file, we will create login form to implement admin login to allow access to logged in user only.

Admin Login



Admin: [email protected]
password:123

We will implement user login on login form submit by calling method adminLogin() from class School.php

include(‘class/School.php’);
$school = new School();
$school->adminLogin();

In class School.php, we will implement method adminLogin().

public function adminLogin(){
$errorMessage=””;
if(!empty($_POST[“login”]) && $_POST[“email”]!=”&& $_POST[“password”]!=”) {
$email = $_POST[’email’];
$password = $_POST[‘password’];
$sqlQuery = “SELECT * FROM “.$this->userTable.”
WHERE email=””.$email.”” AND password='”.md5($password).”‘ AND status=”active” AND type=”administrator””;
$resultSet = mysqli_query($this->dbConnect, $sqlQuery) or die(“error”.mysql_error());
$isValidLogin = mysqli_num_rows($resultSet);
if($isValidLogin){
$userDetails = mysqli_fetch_assoc($resultSet);
$_SESSION[“adminUserid”] = $userDetails[‘id’];
$_SESSION[“admin”] = $userDetails[‘first_name’].” “.$userDetails[‘last_name’];
header(“location: dashboard.php”);
} else {
$errorMessage = “Invalid login!”;
}
} else if(!empty($_POST[“login”])){
$errorMessage = “Enter Both user and password!”;
}
return $errorMessage;
}

Step3: Manage Teachers Section
In teacher.php file, we will create design to add new teacher details edit and display teacher list.

Teachers Section


ID Name Assigned Subjects Class Sections

We will call School class methods addTeacher(), updateTeacher and listTeacher() to handle teachers functionality.

public function listTeacher(){
$sqlQuery = “SELECT t.teacher_id, t.teacher, s.subject, c.name, se.section
FROM “.$this-/button<'; $teacherRows[] = '>button type=”button” name=”delete” id=”‘.$teacher[“teacher_id”].'” class=”btn btn-danger btn-xs delete” /button<'; $teacherData[] = $teacherRows; } $output = array( "draw" =< intval($_POST["draw"]), "recordsTotal" =< $numRows, "recordsFiltered" =< $numRows, "data" =< $teacherData ); echo json_encode($output); } Step4: Manage Student Sections In students.php file, we will design to display student list, save new student admission, update and delete student details.

Student Section


ID Reg No Roll No Name Photo Class Section

We will call School class methods addStudent(), updateStudent, deleteStudent and listStudent() to handle teachers functionality.

public function listStudent(){
$sqlQuery = “SELECT s.id, s.name, s.photo, s.gender, s.dob, s.mobile, s.email, s.current_address, s.father_name, s.mother_name,s.admission_no, s.roll_no, s.admission_date, s.academic_year, c.name as class, se.section
FROM “.$this->studentTable.” as s
LEFT JOIN “.$this->classesTable.” as c ON s.class = c.id
LEFT JOIN “.$this->sectionsTable.” as se ON s.section = se.section_id “;
if(!empty($_POST[“search”][“value”])){
$sqlQuery .= ‘ WHERE (s.id LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR s.name LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR s.gender LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR s.mobile LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR s.admission_no LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR s.roll_no LIKE “%’.$_POST[“search”][“value”].’%” ‘;
}
if(!empty($_POST[“order”])){
$sqlQuery .= ‘ORDER BY ‘.$_POST[‘order’][‘0’][‘column’].’ ‘.$_POST[‘order’][‘0’][‘dir’].’ ‘;
} else {
$sqlQuery .= ‘ORDER BY s.id DESC ‘;
}
if($_POST[“length”] != -1){
$sqlQuery .= ‘LIMIT ‘ . $_POST[‘start’] . ‘, ‘ . $_POST[‘length’];
}
$result = mysqli_query($this->dbConnect, $sqlQuery);
$numRows = mysqli_num_rows($result);
$studentData = array();
while( $student = mysqli_fetch_assoc($result) ) {
$studentRows = array();
$studentRows[] = $student[‘id’];
$studentRows[] = $student[‘admission_no’];
$studentRows[] = $student[‘roll_no’];
$studentRows[] = $student[‘name’];
$studentRows[] = ““;
$studentRows[] = $student[‘class’];
$studentRows[] = $student[‘section’];
$studentRows[] = ‘‘;
$studentRows[] = ‘‘;
$studentData[] = $studentRows;
}
$output = array(
“draw” => intval($_POST[“draw”]),
“recordsTotal” => $numRows,
“recordsFiltered” => $numRows,
“data” => $studentData
);
echo json_encode($output);
}

Step5: Manage Classes Section
In classes.php file, we will design HTML to handle classes functionality like create class, update class, delete class and list classes.

Classes Section


ID Name Sections Class Teacher

We will call School class methods addClass(), updateClass, deleteClass and listClasses() to handle classes functionality.

public function listClasses(){
$sqlQuery = “SELECT c.id, c.name, s.section, t.teacher
FROM “.$this->classesTable.” as c
LEFT JOIN “.$this->sectionsTable.” as s ON c.section = s.section_id
LEFT JOIN “.$this->teacherTable.” as t ON c.teacher_id = t.teacher_id “;
if(!empty($_POST[“search”][“value”])){
$sqlQuery .= ‘ WHERE (c.id LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR c.name LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR s.section LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR t.teacher LIKE “%’.$_POST[“search”][“value”].’%” ‘;
}
if(!empty($_POST[“order”])){
$sqlQuery .= ‘ORDER BY ‘.$_POST[‘order’][‘0’][‘column’].’ ‘.$_POST[‘order’][‘0’][‘dir’].’ ‘;
} else {
$sqlQuery .= ‘ORDER BY c.id DESC ‘;
}
if($_POST[“length”] != -1){
$sqlQuery .= ‘LIMIT ‘ . $_POST[‘start’] . ‘, ‘ . $_POST[‘length’];
}
$result = mysqli_query($this->dbConnect, $sqlQuery);
$numRows = mysqli_num_rows($result);
$classesData = array();
while( $classes = mysqli_fetch_assoc($result) ) {
$classesRows = array();
$classesRows[] = $classes[‘id’];
$classesRows[] = $classes[‘name’];
$classesRows[] = $classes[‘section’];
$classesRows[] = $classes[‘teacher’];
$classesRows[] = ‘‘;
$classesRows[] = ‘‘;
$classesData[] = $classesRows;
}
$output = array(
“draw” => intval($_POST[“draw”]),
“recordsTotal” => $numRows,
“recordsFiltered” => $numRows,
“data” => $classesData
);
echo json_encode($output);
}

Step6: Manage Subjects Section
In subjects.php file, we will design page to handle functionality to add new subjects, update, delete and list subjects.

Subjects Section


ID Subject Code Subject Type

We will call School class methods addSubject(), updateSubject, deleteSubject and listSubject() to handle Subjects functionality.

public function listSubject(){
$sqlQuery = “SELECT subject_id, subject, type, code
FROM “.$this->subjectsTable.” “;
if(!empty($_POST[“search”][“value”])){
$sqlQuery .= ‘ WHERE (subject_id LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR subject LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR type LIKE “%’.$_POST[“search”][“value”].’%” ‘;
$sqlQuery .= ‘ OR code LIKE “%’.$_POST[“search”][“value”].’%” ‘;
}
if(!empty($_POST[“order”])){
$sqlQuery .= ‘ORDER BY ‘.$_POST[‘order’][‘0’][‘column’].’ ‘.$_POST[‘order’][‘0’][‘dir’].’ ‘;
} else {
$sqlQuery .= ‘ORDER BY subject_id DESC ‘;
}
if($_POST[“length”] != -1){
$sqlQuery .= ‘LIMIT ‘ . $_POST[‘start’] . ‘, ‘ . $_POST[‘length’];
}
$result = mysqli_query($this->dbConnect, $sqlQuery);
$numRows = mysqli_num_rows($result);
$subjectData = array();
while( $subject = mysqli_fetch_assoc($result) ) {
$subjectRows = array();
$subjectRows[] = $subject[‘subject_id’];
$subjectRows[] = $subject[‘subject’];
$subjectRows[] = $subject[‘code’];
$subjectRows[] = $subject[‘type’];
$subjectRows[] = ‘‘;
$subjectRows[] = ‘‘;
$subjectData[] = $subjectRows;
}
$output = array(
“draw” => intval($_POST[“draw”]),
“recordsTotal” => $numRows,
“recordsFiltered” => $numRows,
“data” => $subjectData
);
echo json_encode($output);
}

Step7: Manage Student Attendance Section
In attendance.php file, we will design HTML to search class and section student attendance and list. We will also create student attendance form to handle students attendance functionality.

Student Attendance Section

Select Criteria

*

*




We will implement class section student serach functionality to perform student attendance.

$(‘#search’).click(function(){
$(‘#studentList’).removeClass(‘hidden’);
$(‘#saveAttendance’).removeClass(‘hidden’);
if ($.fn.DataTable.isDataTable(“#studentList”)) {
$(‘#studentList’).DataTable().clear().destroy();
}
var classid = $(‘#classid’).val();
var sectionid = $(‘#sectionid’).val();
if(classid && sectionid) {
$.ajax({
url:”action.php”,
method:”POST”,
data:{classid:classid, sectionid:sectionid, action:”attendanceStatus”},
success:function(data) {
$(‘#message’).text(data).removeClass(‘hidden’);
}
})
$(‘#studentList’).DataTable({
“lengthChange”: false,
“processing”:true,
“serverSide”:true,
“order”:[],
“ajax”:{
url:”action.php”,
type:”POST”,
data:{classid:classid, sectionid:sectionid, action:’getStudents’},
dataType:”json”
},
“columnDefs”:[
{
“targets”:[0],
“orderable”:false,
},
],
“pageLength”: 10
});
}
});

We will also implement students attendance functionality bu handle form submit.

$(“#attendanceForm”).submit(function(e) {
var formData = $(this).serialize();
$.ajax({
url:”action.php”,
method:”POST”,
data:formData,
success:function(data){
$(‘#message’).text(data).removeClass(‘hidden’);
}
});
return false;
});

We will handle student attendance update functionality by calling method updateAttendance() from class School.php.

public function updateAttendance(){
$attendanceYear = date(‘Y’);
$attendanceMonth = date(‘m’);
$attendanceDay = date(‘d’);
$attendanceDate = $attendanceYear.”/”.$attendanceMonth.”/”.$attendanceDay;
$sqlQuery = “SELECT * FROM “.$this->attendanceTable.”
WHERE class_id = ‘”.$_POST[“att_classid”].”‘ AND section_id = ‘”.$_POST[“att_sectionid”].”‘ AND attendance_date=””.$attendanceDate.”””;
$result = mysqli_query($this->dbConnect, $sqlQuery);
$attendanceDone = mysqli_num_rows($result);
if($attendanceDone) {
foreach($_POST as $key => $value) {
if (strpos($key, “attendencetype_”) !== false) {
$student_id = str_replace(“attendencetype_”,””, $key);
$attendanceStatus = $value;
if($student_id) {
$updateQuery = “UPDATE “.$this->attendanceTable.” SET attendance_status=””.$attendanceStatus.””
WHERE student_id = ‘”.$student_id.”‘ AND class_id = ‘”.$_POST[“att_classid”].”‘ AND section_id = ‘”.$_POST[“att_sectionid”].”‘ AND attendance_date=””.$attendanceDate.”””;
mysqli_query($this->dbConnect, $updateQuery);
}
}
}
echo “Attendance updated successfully!”;
} else {
foreach($_POST as $key => $value) {
if (strpos($key, “attendencetype_”) !== false) {
$student_id = str_replace(“attendencetype_”,””, $key);
$attendanceStatus = $value;
if($student_id) {
$insertQuery = “INSERT INTO “.$this->attendanceTable.”(student_id, class_id, section_id, attendance_status, attendance_date)
VALUES (‘”.$student_id.”‘, ‘”.$_POST[“att_classid”].”‘, ‘”.$_POST[“att_sectionid”].”‘, ‘”.$attendanceStatus.”‘, ‘”.$attendanceDate.”‘)”;
mysqli_query($this->dbConnect, $insertQuery);
}
}

}
echo “Attendance save successfully!”;
}
}

You may also like:
You can view the live demo from the Demo link and can download the script from the Download link below.Demo Download

Coded at

Share your love

Leave a Reply