0

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.

3
  • 1
    replace this => echo 'Marks entered for: '.$student.' average is'.(($total*0.4)+($mock_mark)); Commented Nov 14, 2016 at 8:38
  • Thanks @SoniVimal Commented Nov 14, 2016 at 10:11
  • check below my answer is it proper for you ? Commented Nov 14, 2016 at 10:12

3 Answers 3

2

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));
Sign up to request clarification or add additional context in comments.

Comments

1

When you do

'text' + 4

this is mathematical operation. If you want to add some number + number to text you must use () for all result, so in your example will be

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

No we are concatenate text with some mathematical result

Comments

0

replace this =>

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.