<?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 session_start(); if (!isset($_SESSION['teacher_id'])) header('Location: ../login.php'); exit(); include('../config/db_connection.php');$teacher_id = $_SESSION['teacher_id']; $query = "SELECT class_id FROM teachers WHERE id='$teacher_id'"; $result = mysqli_query($conn, $query); $teacher = mysqli_fetch_assoc($result); $class_id = $teacher['class_id'];
if (isset($_POST['submit_attendance'])) $date = $_POST['date']; foreach ($_POST['attendance'] as $student_id => $status) $insert = "INSERT INTO attendance (student_id, class_id, date, status) VALUES ('$student_id', '$class_id', '$date', '$status')"; mysqli_query($conn, $insert); echo "Attendance saved for $date"; school management system project with source code in php
// Fetch students of this class $students = mysqli_query($conn, "SELECT * FROM students WHERE class_id='$class_id'"); ?> <form method="post"> <input type="date" name="date" required> <table border="1"> <tr><th>Student Name</th><th>Status</th></tr> <?php while($student = mysqli_fetch_assoc($students)) ?> <tr> <td><?php echo $student['student_name']; ?></td> <td> <select name="attendance[<?php echo $student['id']; ?>]"> <option>Present</option> <option>Absent</option> <option>Late</option> </select> </td> </tr> <?php ?> </table> <button type="submit" name="submit_attendance">Save Attendance</button> </form>
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. // Fetch students of this class $students =
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 = ?.
| Component | Technology | |----------------|--------------------------------------| | Frontend | HTML5, CSS3, Bootstrap 5, JavaScript | | Backend | PHP 7.4+ / 8.x (procedural or OOP) | | Database | MySQL 5.7+ / MariaDB | | Server | Apache / XAMPP / WAMP / Laragon | | Additional JS | jQuery (optional), Chart.js (graphs) | else echo "Invalid credentials"
// login.php session_start(); include 'db.php';$email = $_POST['email']; $password = md5($_POST['password']); // Use password_hash() in production
$query = "SELECT * FROM users WHERE email='$email' AND password='$password'"; $result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) == 1) $user = mysqli_fetch_assoc($result); $_SESSION['user_id'] = $user['id']; $_SESSION['role'] = $user['role']; // admin, teacher, student
if($user['role'] == 'admin') header("Location: admin/dashboard.php"); elseif($user['role'] == 'teacher') header("Location: teacher/dashboard.php"); else header("Location: student/dashboard.php");
else echo "Invalid credentials";