Student Grading System in PHP and MySQL
Student Grading System in PHP and MySQL
Most of my career as programmer spend developing programs using PHP and MySQL. In this article I
would like to share my program that I wrote a long time ago I called this program Student Grading
System in PHP and MySQL. This program will compute and store the grades of the student in MySQL.
Feel free to use my code in your programming projects at school or work. If you have some questions
please send me an email at.com and [email protected].
Program Listing
grade.php
<?php
Tool : PHP/MySQL
*/
error_reporting(0);
?>
<?php
$name =$_REQUEST['name'];
$course = $_REQUEST['course'];
$sex = $_REQUEST['sex'];
$department = $_REQUEST['department'];
$subject =$_REQUEST['subject'];
$contact = $_REQUEST['contact'];
if (isset($_REQUEST['solve']))
$prelim = $_REQUEST['prelim'];
$midterm = $_REQUEST['midterm'];
$final = $_REQUEST['final'];
$endterm = round($add);
$remarks = "PASSED";
else {
$remarks = "FAILED";
if (isset($_REQUEST['clear']))
$name = "";
$course = "";
$subject="";
$department = "";
$contact = "";
$prelim = "";
$midterm = "";
$final = "";
$endterm = "";
$remarks = "";
if (isset($_REQUEST['save']))
$name = strtoupper($_REQUEST['course']);
$course = strtoupper($_REQUEST['course']);
$deparment = strtoupper($_REQUEST['department']);
$sex = strtoupper($_REQUEST['sex']);
$contact = $_REQUEST['contact'];
$prelim = $_REQUEST['prelim'];
$midterm = $_REQUEST['midterm'];
$final = $_REQUEST['final'];
$endterm = $_REQUEST['endterm'];
$remarks = strtoupper($_REQUEST['remarks']);
//CONNECT TO DATABASE--------------------
$con = mysql_connect("localhost","root","");
if (!$con)
mysql_select_db("grade", $con);
/*
* Specify the field names that are in the form. This is meant
* to the form.
*/
$allowedFields = array(
'name',
'course',
'subject',
'department',
'contact',
'prelim',
'midterm',
'final',
'endterm',
'remarks'
);
$requiredFields = array(
'name',
'course',
'subject',
'department',
'contact',
'prelim',
'midterm',
'final'
);
$errors = array();
if(in_array($key, $allowedFields))
$$key = $value;
if(count($errors) > 0)
$errorString .= '<ul>';
foreach($errors as $error)
$errorString .= "<li>$error</li>";
$errorString .= '</ul>';
echo $errorString;
else {
$sql .= "VALUES";
if(!$b=mysql_query($sql)){
echo mysql_error();
else {
echo "<center>";
echo "</center>";
}
}
?>
<html>
<head>
<STYLE type="text/css">
h2 {
text-align:center;
/* No borders set */
</STYLE>
</head>
<body>
<br>
<TABLE BORDER="0">
<tr> </tr> <tr> </tr>
<TR>
<TD>Student Name</TD>
<TD>
<TD> Course</TD>
<TD>
</TD>
</TR>
<TR>
<TD>Prelim Grade</TD>
</TD>
<TD>Subject</TD>
<TD>
<INPUT TYPE="TEXT" NAME="subject" SIZE="35" MAXLENGTH=35
</TD>
</TR>
<TR>
<TD>Midterm Grade</TD>
</TD>
<TD>Department</TD>
<TD>
</TD>
</TR>
<TR>
<TD>Final Grade</TD>
</TD>
<TD>Gender</TD>
<td> <select name="sex">
<option>Male</option>
<option>Female</option>
</select>
</td>
</tr>
<tr>
<TD>Endterm Grade</TD>
</TD>
<TD>Contact Number</TD>
<TD>
</TD>
</tr>
<tr>
<TD>Remarks</TD>
<TD>
</TD>
</TR>
</TABLE>
</P>
</FORM>
</body>
</html>
grade.sql
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
--
-- Database: `grade`
--
-- --------------------------------------------------------
--
--
--
--
INSERT INTO `info` (`name`, `course`, `subject`, `department`, `gender`, `contact`, `prelim`, `midterm`,
`final`, `endterm`, `remarks`) VALUES
('Jake Pomperada', 'BS Computer Science', 'Pascal Programming', 'Commerce', 'MALE', 4335081, 78, 89,
95, 90, 'PASSED'),
('Ma. Junallie Fuentebella', 'BS Chemical Engineering', 'Chemistry 1', 'Engineering', 'FEMALE', 4335675,
89, 78, 100, 91, 'PASSED'),
('Ana Tan', 'BS Accountancy', 'Financial Management', 'Commerce', 'FEMALE', 7078423, 78, 78, 79, 79,
'PASSED'),
('Tita Swarding', 'Mass Communication', 'Basic Journalism', 'Arts and Sciences', 'FEMALE', 7546348, 87,
89, 94, 91, 'PASSED'),
('Vincent Qui', 'BS Business Management', 'Accouting 101', 'Commerce', 'MALE', 999237563, 74, 83, 84,
82, 'PASSED'),
('Boy Cruz', 'BS Mathematics', 'Calculus', 'Education', 'MALE', 4567812, 65, 72, 76, 73, 'FAILED'),
('Juan Tamad', 'BS Secondary Education', 'Physical Education', 'Education', 'MALE', 4235562, 73, 65, 71,
70, 'FAILED');