Neliswa Astute Neliswa Astute - 19 days ago 5
MySQL Question

Incorrect arithmetic output

I have this piece of code that inserts marks in to the database, but the problem is that

$sql_insert=mysqli_query($conn,"INSERT INTO `marks_1c`

(student_name,test_1,test_2,test_3,test_4,test_5,mock,teacher,subject)
VALUES('$student',
'$test_1',
'$test_2',
'$test_3',
'$test_4',
'$test_5',
'$mock',
'$session',
'$subject')")or die(mysqli_error($conn)); if($sql_insert){
$total=($test_1+$test_2+$test_3+$test_4+$test_5)/5;
$mock_mark=$mock*0.6;
echo 'Marks entered for '.$student.' '.'average is '.($total*0.4)+($mock_mark);


when I run this code, it does not echo the "Marks entered for '.$student.' '.'average is" but it only displays the result of ($total*0.4)+($mock_mark).

But when, I put the multiply the ($total*0.4) and ($mock_mark), it displays the "Marks entered for '.$student.' '.'average is"

i do not understand, please help.

Answer

Following code will workout

$mark = ($total*0.4)+($mock_mark);

echo "Marks entered for ".$student." "."average is".$mark;

or

echo 'Marks entered for '.$student.' '.'average is '.(($total*0.4)+($mock_mark));
Comments