Search
Student Grading System with Report Card and GWA using PHP and MySQL with Source Code
The Student Grading System is a web application built with PHP and MySQL for schools, colleges and student capstone projects. Teachers encode Prelim, Midterm and Finals grades in one grade sheet, and the system computes each student's weighted average, the equivalent 1.00 to 5.00 grade, and the remarks (Passed, Failed or Incomplete). Admins manage students, subjects, classes and teacher accounts, and anyone signed in can print a student's report card with the General Weighted Average (GWA).
The project uses plain PHP with PDO, so it is easy to read and extend. It runs on XAMPP, Laragon or any PHP 8 server, and the included database.sql loads sample students, subjects, classes and grades so you can try every feature right away. The full source code is free to download below.
Student Grading System Basic Information
- Language used: PHP 8.0+ (tested with PHP 8.3)
- Database used: MySQL or MariaDB via PDO (tested with MariaDB 11.8)
- Front end: Plain HTML and CSS, print-friendly (no CDN required)
- Coding Tool used: VS Code, PHPStorm or any text editor
- Type: Web Application
About the Student Grading System
Many teachers still compute grades in a spreadsheet, copy the results by hand, and then retype them for the registrar. Formulas get overwritten, a missing finals grade quietly turns into zero, and it is hard to see which students are failing until the end of the term.
This system keeps everything in one database. An administrator creates subjects and classes (subject + section + school year + semester), assigns a teacher, and enrolls students. The teacher opens the class grade sheet, types the three term grades, and clicks Save Grades. The averages, grade points and remarks update immediately. If a term is still blank, the student is marked Incomplete instead of being failed by mistake. The dashboard shows a passing rate for every class, so problems are visible early.
Features
- Secure login with
password_hash()/password_verify()and two roles: Admin and Teacher. - Dashboard with totals and a class summary: enrolled, passed, failed, incomplete and passing rate.
- Student management: add, edit, delete and search by student number, name or course; duplicate student numbers are blocked.
- Subject management with code, title and units; a subject that is used by a class cannot be deleted.
- Class management: subject, teacher, section, school year and semester, with a check against duplicate sections in the same term.
- Enrollment: tick students to enroll them in a class, or remove them.
- Grade sheet: encode Prelim, Midterm and Finals (0 to 100) for the whole class in one form, with validation.
- Automatic computation: weighted average (30% / 30% / 40% by default), 1.00 to 5.00 grade point, and remarks.
- Report card per student and term with units, grades, GWA and units earned, ready to print.
- Access control: teachers see and grade only their own classes; only admins manage users, subjects, classes and enrollment.
- Safer code: PDO prepared statements, CSRF tokens on every form, and escaped output.
Screenshots
These screenshots were taken from the running application with the included sample data. The dashboard is the main screenshot; the additional shots show the login page, the class grade sheet, a teacher's grade sheet with an incomplete grade, the printable report card, and the students, subjects, classes, new class and users pages.
Code Highlights
All the grading rules live in includes/functions.php. The weights and passing mark come from config.php, so you can match your school's policy without touching the logic. A missing term returns null, which becomes Incomplete instead of a failing grade:
- /** Weighted average of the three terms, or null if a term is missing. */
- function compute_average($prelim, $midterm, $finals): ?float {
- if ($prelim === null || $midterm === null || $finals === null) {
- return null;
- }
- $avg = ($prelim * WEIGHT_PRELIM + $midterm * WEIGHT_MIDTERM + $finals * WEIGHT_FINALS) / 100;
- }
- /** Converts a 0-100 average to the common 1.00 - 5.00 grade point scale. */
- function grade_point(?float $avg): ?string {
- if ($avg === null) return null;
- $scale = [97 => '1.00', 94 => '1.25', 91 => '1.50', 88 => '1.75', 85 => '2.00',
- 82 => '2.25', 79 => '2.50', 76 => '2.75', 75 => '3.00'];
- foreach ($scale as $min => $gp) {
- if ($a >= $min) return $gp;
- }
- return '5.00';
- }
- function remarks(?float $avg): string {
- if ($avg === null) return 'Incomplete';
- }
Saving the grade sheet validates every box first, then updates all rows inside one transaction, so a typo like 150 never leaves the class half-saved:
- if ($action === 'save') {
- $rows = $_POST['g'] ?? [];
- $clean = [];
- foreach ($rows as $sid => $terms) {
- foreach (['prelim', 'midterm', 'finals'] as $t) {
- [$ok, $val] = parse_grade($terms[$t] ?? '');
- if (!$ok) $errors[] = "Invalid $t grade for student #$sid. Use a number from 0 to 100.";
- $clean[(int)$sid][$t] = $val;
- }
- }
- if (!$errors) {
- $upd = $pdo->prepare('UPDATE enrollments SET prelim = ?, midterm = ?, finals = ?, updated_at = NOW()
- WHERE class_id = ? AND student_id = ?');
- $pdo->beginTransaction();
- foreach ($clean as $sid => $t) {
- $upd->execute([$t['prelim'], $t['midterm'], $t['finals'], $classId, $sid]);
- }
- $pdo->commit();
- redirect('grades.php?class_id=' . $classId);
- }
- }
Teachers can only open their own classes. Every grade page calls this check before showing or saving anything:
- /** Teachers may only open their own classes. */
- return is_admin() || (int)$class['teacher_id'] === (int)current_user()['id'];
- }
The report card computes the GWA from the grade points weighted by units, using only completed subjects:
- $totalUnits = 0; $weighted = 0; $complete = true; $earned = 0;
- foreach ($rows as &$r) {
- $r['avg'] = compute_average($r['prelim'], $r['midterm'], $r['finals']);
- $r['gp'] = grade_point($r['avg']);
- $r['remarks'] = remarks($r['avg']);
- if ($r['gp'] === null) { $complete = false; continue; }
- $totalUnits += $r['units'];
- $weighted += $r['units'] * (float)$r['gp'];
- if ($r['remarks'] === 'Passed') $earned += $r['units'];
- }
Database Tables
There are five tables: users, students, subjects, classes and enrollments. The grades live in enrollments, one row per student per class. Deleting a class or a student also removes the related grade rows through ON DELETE CASCADE:
- CREATE TABLE enrollments (
- class_id INT NOT NULL,
- student_id INT NOT NULL,
- prelim DECIMAL(5,2) NULL,
- midterm DECIMAL(5,2) NULL,
- finals DECIMAL(5,2) NULL,
- updated_at DATETIME NULL,
- PRIMARY KEY (class_id, student_id),
- FOREIGN KEY (class_id) REFERENCES classes(id) ON DELETE CASCADE,
- FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE
- ) ENGINE=InnoDB;
Project Structure
student-grading-system/ ├── config.php database settings, grading weights, passing grade ├── database.sql tables + sample data ├── login.php / logout.php ├── index.php dashboard and class summary ├── students.php / student_form.php ├── subjects.php ├── classes.php / class_form.php ├── grades.php grade sheet, enrollment ├── report_card.php printable report card with GWA ├── users.php admin: teacher and admin accounts ├── assets/style.css └── includes/ db.php, auth.php, functions.php, header.php, footer.php
How to Run the Student Grading System
Requirements
- XAMPP, Laragon or WAMP (PHP 8.0 or newer with
pdo_mysql) - MySQL 5.7/8.x or MariaDB 10.4 or newer
Installation
- Download the source code zip below and extract it.
- Copy the
student-grading-systemfolder toC:\xampp\htdocs\. - Open the XAMPP Control Panel and start Apache and MySQL.
- Go to
http://localhost/phpmyadmin, click Import, choosedatabase.sqland click Go. This creates thestudent_gradingdatabase with sample data. - If your MySQL root account has a password, open
config.phpand setDB_PASS. - Open
http://localhost/student-grading-system/in your browser.
Default accounts:
- Admin:
admin/admin123 - Teacher:
mreyes/teacher123andjdelacruz/teacher123
Before publishing the project for review, the included smoke test (login, CRUD, enrollment, grade validation and computation, report card, teacher access rules and CSRF check) was run against PHP 8.3 and MariaDB 11.8 with the result: 29 passed, 0 failed.
Ideas to Extend the Project
- Student portal where students log in and view their own grades.
- Import a class list or grades from a CSV file.
- Grade components per term (quizzes, exams, projects) instead of one term grade.
- Lock grades after the registrar approves them, with an audit log of changes.
- Export the grade sheet and report card to PDF or Excel.
Conclusion
The Student Grading System is a complete PHP and MySQL project that covers what schools actually need: classes, enrollment, a fast grade sheet, automatic averages and grade points, and a printable report card with GWA. It is a good base for a capstone project, and the code is short enough to study in an afternoon. Adjust the weights and grade scale in the config to match your school.
Note: the default accounts are for testing only. Change the passwords after your first login, and review access rules before using real student records.
Download the complete source code below. Happy coding!
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.