0

Hello Guys. i need ur help. I want to compute the grades in php. This is My code.

<?php
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("collegestudent") or die(mysql_error());

$id = $_POST['id'];
$prelim = $_POST['prelim'];
$midterm = $_POST['midterm'];
$prefinal = $_POST['prefinal'];
$final = $_POST['final'];
$a = (int) $prelim + 50 * .20;
$b=(int) $midterm + 50 * .20;
$c = (int) $prefinal + 50 * .20;
$d = (int) $final + 50 * .40;
$grades =0;
$grades = (int) $a+(int) $b+(int) $c+(int) $d;
$remarks = "PASS";


$sql="INSERT INTO tblgrade (StudentID, Prelim, Midterm, Pre_Final, Final, Grades, Remarks) VALUES('$id','$midterm','$prefinal','$final', '$grades', '$remarks')";
$query= mysql_query($sql);
mysql_close();
header('location:student_grades.php');
?>

i dont know it correct or wrong.
after computing the grades i want to save it in the database. the problem is If i click save it wont save in database .. what should i do? thanks in advance

more power

3
Contributors
3
Replies
29
Views
4 Years
Discussion Span
Last Post by diafol
0

At first sight, your SQL query has an error: you're trying to insert 6 values into 7 columns. You probably forgot to pass a value for Prelim hence the problem.

Edited by TheApex

This question has already been answered. 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.