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

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.

Same Problem if add $prelim in SQL query.

Member Avatar for diafol
$query= mysql_query($sql) or die(mysql_error());

See what it says.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.