Neliswa Astute Neliswa Astute - 1 year ago 67
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`

'$subject')")or die(mysqli_error($conn)); if($sql_insert){
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 Source

Following code will workout

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

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


echo 'Marks entered for '.$student.' '.'average is '.(($total*0.4)+($mock_mark));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download