School Management System Project With Source Code In Php
<?php session_start(); if (!isset($_SESSION['student_id'])) header('Location: ../login.php'); exit(); include('../config/db_connection.php');$student_id = $_SESSION['student_id'];
$query = "SELECT subjects.subject_name, exam_marks.marks_obtained, exam_marks.exam_name FROM exam_marks JOIN subjects ON exam_marks.subject_id = subjects.id WHERE exam_marks.student_id='$student_id'";
$result = mysqli_query($conn, $query); ?>
<h2>My Exam Results</h2> <table border="1"> <tr><th>Subject</th><th>Exam</th><th>Marks</th></tr> <?php while($row = mysqli_fetch_assoc($result)) ?> <tr> <td><?php echo $row['subject_name']; ?></td> <td><?php echo $row['exam_name']; ?></td> <td><?php echo $row['marks_obtained']; ?></td> </tr> <?php ?> </table>
School Management System (PHP & MySQL)
Q1: Can I modify this project for a college or university?
Yes. You can add departments, multiple campuses, hostel management, and library modules.
Q2: Is the source code free to use?
Most educational PHP projects are open-source under the MIT or GPL license. Check the license file included. school management system project with source code in php
Q3: How do I change the school name and logo?
Update the SCHOOL_NAME constant in config/settings.php and replace the logo in assets/images/.
Q4: Can I host this online?
Absolutely. Upload to any shared hosting that supports PHP and MySQL (e.g., Hostinger, Bluehost, GoDaddy).
Q5: How to prevent parents from seeing other children's data?
Use foreign key mapping: parent_id in students table → user_id in users table with role 'parent'. Then filter queries by WHERE parent_id = ?.
File: modules/teacher/attendance.php
<?php require_once '../../config/database.php'; $class_id = $_GET['class_id'] ?? 1; $date = date('Y-m-d');// Fetch students of this class $stmt = $pdo->prepare("SELECT s.student_id, s.first_name, s.last_name FROM students s WHERE s.class_id = ?"); $stmt->execute([$class_id]); $students = $stmt->fetchAll();
if ($_SERVER['REQUEST_METHOD'] == 'POST') foreach ($_POST['attendance'] as $student_id => $status) $insert = $pdo->prepare("INSERT INTO attendance (student_id, date, status, class_id) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE status = ?"); $insert->execute([$student_id, $date, $status, $class_id, $status]); $msg = "Attendance saved!"; ?>
<?php session_start(); include('config/db_connect.php');if($_SERVER["REQUEST_METHOD"] == "POST") $username = $_POST['username']; $password = md5($_POST['password']);
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'"; $result = $conn->query($sql); if($result->num_rows == 1) $row = $result->fetch_assoc(); $_SESSION['user_id'] = $row['id']; $_SESSION['role'] = $row['role']; header("Location: dashboard.php"); else echo "Invalid login";
?>
File: modules/admin/add_student.php
<?php require_once '../../config/database.php'; require_once '../../includes/auth.php';if ($_SERVER['REQUEST_METHOD'] == 'POST') // Insert into users table first $username = $_POST['admission_no']; $hashed_password = password_hash($_POST['password'], PASSWORD_DEFAULT); $role = 'student';
$user_stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, ?)"); $user_stmt->execute([$username, $hashed_password, $role]); $user_id = $pdo->lastInsertId(); // Insert into students table $stmt = $pdo->prepare("INSERT INTO students (user_id, admission_no, first_name, last_name, dob, class_id, section_id) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$user_id, $_POST['admission_no'], $_POST['first_name'], $_POST['last_name'], $_POST['dob'], $_POST['class_id'], $_POST['section_id']]); $success = "Student added successfully!";
?>
<?php $host = 'localhost'; $user = 'root'; $password = ''; $database = 'school_management';$conn = mysqli_connect($host, $user, $password, $database);
if (!$conn) die("Connection failed: " . mysqli_connect_error()); ?>
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "school_management";$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error); ?>