Press "Enter" to skip to content

PHP Form Example – Student Grading System

Here is a PHP program with four text fields and a submit button for calculating the total marks, displaying the grade for a student in a PHP file.

PHP Form Example

In this program, we are creating a <table> tag (defining a table on a web page), <tr> tag(defining a row for a table), <td>tag(defining a cell/data of a table), <center> tag(here it is defining the HTML element in the middle of the web page) and we are passing 4 values (“John Mathew” for first text box, 90 is for second text field, 80 is for third text field, 70 is for 4th text field) and hereafter clicking on submit button, we are getting the result. Here <input type=submit> is defining a submit button.

        <form action="" method="post">
                <table border=0>
                            Student Name
                            <input type=text name="t1">
                            Marks for Physics
                            <input type=text name="t2">
                            Marks for Chemistry
                            <input type=text name="t3">
                            Marks for Math
                            <input type=text name="t4">
                <input type=submit name="s" value="Result">
if(isset($_POST['s']))////checking whether the input element is set or not
    $a=$_POST['t1']; //accessing value from 1st text box
    $a1=$_POST['t2']; //accessing value from 2nd text field
    $a2=$_POST['t3']; //accessing value from 3rd text field
    $a3=$_POST['t4']; //accessing value from 4th text field
    $sum=$a1+$a2+$a3; //total marks
    echo "<br>";
    echo "<font size=4><center>Student is:-".$a."</center><br>"; 
    echo "<font size=4><center>Total marks:-".$sum."</center><br>"; 
    echo "<font size=4><center>Grade is:-".$grade."</center>"; 

Output (as shown in the featured image of this article)

Student is:- John Mathew

Total marks:- 240

The grade is:- B

This program is containing some conditions, based on one condition using an if-else statement we are displaying the grade of the student.

Have you found the answer to your question? If not, you can discuss it with me in the comments section below or join my Q&A community for developers and ask your question. It is FREE.

Vinish Kapoor


Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Inline Feedbacks
View all comments