0

Hello. :) So I am creating a grading system where users can compute student's grades on selected ID Number. The problem is after clicking the COMPUTE button, an "Error!" message display. So far I can save the grades in database but I can't compute it. I'm sorry I'm new to PHP. Here is my code so far:

<?php
 function renderForm($ID, $FirstName, $LastName, $Attendance, $Quiz, $MidtermExam, $FinalExam, $FinalGrade, $Remarks, $error)
 {
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
 <title>COMPUTE GRADE</title>
 </head>
 <body>
 <?php 
 if ($error != '')
 {
 echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?> 
 
 <form action="grade1.php" method="POST">

<td>&nbsp;</td>
<br /><td>&nbsp;</td><label>ID Number: </label><input type="text" name="ID" value="<?php echo $ID; ?>" READONLY /><br />
<br /><td>&nbsp;</td><label>First Name: </label><input type="text" name="FirstName" value="<?php echo $FirstName; ?>" READONLY /><br />
<br /><td>&nbsp;</td><label>Last Name: </label><input type="text" name="LastName" value="<?php echo $LastName; ?>" READONLY /><br /><br />

<br /><td>&nbsp;</td><label>Attendance: </label><input type="text" name="Attendance" value="<?php echo $Attendance; ?>"/><br /><br />
<br /><td>&nbsp;</td><label>Quiz: </label><input type="text" name="Quiz" value="<?php echo $Quiz; ?>"/><br /><br />
<br /><td>&nbsp;</td><label>Midterm Exam: </label><input type="text" name="MidtermExam" value="<?php echo $MidtermExam; ?>"/><br /><br />
<br /><td>&nbsp;</td><label>Final Exam: </label><input type="text" name="FinalExam" value="<?php echo $FinalExam; ?>"/><br /><br />
<br /><td>&nbsp;</td><label>Final Grade: </label><input type="text" name="FinalGrade" value="<?php echo $FinalGrade; ?>" READONLY /><br /><br />
<br /><td>&nbsp;</td><label>Remarks: </label><input type="text" name="Remarks" value="<?php echo $Remarks; ?>" READONLY /><br /><br />


<br /><td>&nbsp;</td><input type="submit" value="COMPUTE" name="compute"/><br /><br />
<br /><td>&nbsp;</td><input type="submit" value="SAVE" name="save"/><br /><br />
</form>
</body>
</html>

 <?php
 }

 include('collegeinfo_connect.php');

 if (isset($_POST['save']))
 { 

 if (is_numeric($_POST['ID']))
 {

 $ID = mysql_real_escape_string(htmlspecialchars($_POST['ID']));
 $FirstName = mysql_real_escape_string(htmlspecialchars($_POST['FirstName']));
 $LastName = mysql_real_escape_string(htmlspecialchars($_POST['LastName']));
 $Attendance = mysql_real_escape_string(htmlspecialchars($_POST['Attendance']));
 $Quiz = mysql_real_escape_string(htmlspecialchars($_POST['Quiz']));
 $MidtermExam = mysql_real_escape_string(htmlspecialchars($_POST['MidtermExam']));
 $FinalExam = mysql_real_escape_string(htmlspecialchars($_POST['FinalExam']));
 $FinalGrade = mysql_real_escape_string(htmlspecialchars($_POST['FinalGrade']));
 $Remarks = mysql_real_escape_string(htmlspecialchars($_POST['Remarks']));

 if ($ID == '' || $FirstName == '' || $LastName == '' || $Attendance == '' || $Quiz == '' || $MidtermExam == '' || $FinalExam == '' || $FinalGrade == '' || $Remarks == '')
 {

 $error = 'ERROR: Please fill in all required fields!';

 renderForm($ID, $FirstName, $LastName, $Attendance, $Quiz, $MidtermExam, $FinalExam, $FinalGrade, $Remarks, $error);
 }
 else
 {

 mysql_query("UPDATE collegeinfo_tbl SET FirstName='$FirstName', LastName='$LastName', Attendance='$Attendance', Quiz='$Quiz', MidtermExam='$MidtermExam', FinalExam='$FinalExam', FinalGrade='$FinalGrade', Remarks='$Remarks' WHERE ID='$ID'")
 or die(mysql_error()); 

 header("Location: results.php"); 
 }
 }
 else
 {

 echo 'Error!';
 }
 }
 else
 {

 if (isset($_GET['ID']) && is_numeric($_GET['ID']) && $_GET['ID'] > 0)
 {

 $ID = $_GET['ID'];
 $result = mysql_query("SELECT * FROM collegeinfo_tbl WHERE ID=$ID")
 or die(mysql_error()); 
 $row = mysql_fetch_array($result);

 if($row)
 {
 $ID = $row['ID'];
 $FirstName = $row['FirstName'];
 $LastName = $row['LastName'];
 $Attendance = $row['Attendance'];
 $Quiz = $row['Quiz'];
 $MidtermExam = $row['MidtermExam'];
 $FinalExam = $row['FinalExam'];
 $FinalGrade = $row['FinalGrade'];
 $Remarks = $row['Remarks'];

 

 renderForm($ID, $FirstName, $LastName, $Attendance, $Quiz, $MidtermExam, $FinalExam, $FinalGrade, $Remarks, '');
 }
 else
 {
 echo "No results!";
 }
 }
 else
 {
 echo 'Error!'; <-- An error displays after clicking compute button.
 }
 }
 
  if (isset($_POST['compute']))
       {
	   
	   $Attendance = $_POST['Attendance'];
	   $Quiz = $_POST['Quiz'];
       $MidtermExam = $_POST['MidtermExam']; 
	   $FinalExam = $_POST['FinalExam'];
	   
	    $solve1 = ($_POST['Attendance'] * 0.10);
		$solve2 = ($_POST['Quiz'] * 0.30);
		$solve3 = ($_POST['MidtermExam'] * 0.25);
		$solve4 = ($_POST['FinalExam'] * 0.35);
		
		$add = ($solve1 + $solve2 + $solve3 + $solve4);
		
		$FinalGrade = round($add);
		
		if ($add >= 75) 
	  	 {
          $Remarks = "PASSED";
        }
       else {
           $Remarks = "FAILED";
       }	
	}	
?>

Or do you have any simple code for grading system where it can save in database from selected ID number? I hope it made sense. Any help would be appreciated.

Edited by aianne: n/a

3
Contributors
2
Replies
9
Views
5 Years
Discussion Span
Last Post by urtrivedi
0

Hi,

Is this for the faculty and student views? If for both, the student can easily spoof your form, and they can have 100% grades on all of the terms prelim, midterm and finals..


Just my humble advice :). Show the grades to student as text string and NOT on the form system. Provide them with the calculation link using jquery to calculate the grades. The jquery will then print the grades on the targeted div.

Also when calculating isolate each variable and constant with parenthesis.. eg. ((value1 * value2) + (value3 * value4))..

0

Calculation of grade must be one time process and it must be done by faculty or administrator, in that process it should store calculated grades in some table.

Then that calculated grades can be shown to students any other who knows roll number.

Edited by urtrivedi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.