This simple PHP web app allows users to input their name and five grades, then calculates their average (moyenne) and displays a personalized comment depending on whether they passed or failed.
It includes:
- Basic form handling with POST requests.
- Validation to ensure all fields are filled and grades are between 0 and 20.
- Error messages for invalid input.
- A result section showing the student’s name, calculated average, and a comment.
✅ Input of student name and five grades. ✅ Validation for empty fields and invalid grade values. ✅ Average calculation (sum of grades ÷ number of grades). ✅ Friendly output message:
- 🎉 “Félicitations ! vous êtes admis” if average ≥ 10
- 😞 “Malheureusement vous repassez l’examen” if average < 10
- PHP (for backend logic)
- HTML5 (for structure)
- CSS (optional, linked as
style.cssfor styling)
-
Clone or download the project files into your web server directory (e.g.,
htdocsfor XAMPP orwwwfor WAMP). -
Make sure your local PHP server is running (e.g.,
http://localhost). -
Open your browser and go to:
http://localhost/your_project_folder/ -
Fill out the form with your name and five grades.
-
Click “calcul” to see your average and result message.
- Make sure all grades are between 0 and 20.
- The form uses
requiredattributes, but validation is also handled in PHP for security. - You can modify the number of grades by adding or removing
<input>fields in the HTML form and adjusting the PHP logic if needed.
student-average/
│
├── index.php # Main PHP file (contains form and logic)
├── style.css # Optional stylesheet for layout and colors
└── README.md # Project documentation
Input: Name: Ali Notes: 12, 14, 9, 16, 10
Output:
Your name: Ali
Your moyenne: 12.20
Félicitations ! vous êtes admis
- Add support for a dynamic number of grades.
- Include letter grading (A, B, C...) based on average.
- Store results in a database (MySQL).
- Improve UI with Bootstrap or TailwindCSS.