Why is it that when I type in the new exam he continues to do the sum of the new exam with the old average?

Asked

Viewed 48 times

-1

The question is this in php: read four values for a student’s four school grades and print a message saying that the student has passed, if the average school value is greater than or equal to 7. If the average value is less than 7, request the exam grade, add to the mean value and obtain a new mean. If the new average is greater than or equal to 5, present a message saying that the student has passed the exam. If the student has not passed, indicate a message stating this condition. Display together with messages the student’s average value for any condition.

this is the main form:

<!DOCTYPE html>
<html>
<title>Questões</title>
<body>
<form action="q6php.php" method="POST">
 Digite a primeira nota: <input type="number" name="n1"><br>
 Digite a segunda nota: <input type="number" name="n2"><br>
 Digite a terceira nota: <input type="number" name="n3"><br>
 Digite a quarta nota: <input type="number" name="n4"><br>
 <input type="submit" value="Salvar" name="menu">
</form>
</body>
</html>

This is the php:

<?php
$n1 = $_POST['n1'];
$n2 = $_POST['n2'];
$n3 = $_POST['n3'];
$n4 = $_POST['n4'];
$med = (($n1+$n2+$n3+$n4)/4);
if($med>=7){
      echo("aprovado com ". $med);
    }else if($med<7){
    header('location: q6formdir.php');
    $k= $_POST['n5'];
    if(isset($_POST['salvar'])){
       $mednova = (($med + $k)/2);
      if($mednova>=5){
      echo("aprovado em exame com ".$mednova);

}else{
      echo("reprovado");
}
}

    }

?>

and this other is the form that if the average is less than 7 he will ask for another test:

<!DOCTYPE html>
<html>
<title>Questões</title>
<body>
<form action="q6php.php" method="POST">
  Digite a nota do novo exame: <input type="number" name="n5">
  <input type="submit" value="salvar" name="salvar">
  <input type="hidden" value="n1" name="n1">
  <input type="hidden" value="n2" name="n2">
  <input type="hidden" value="n3" name="n3">
  <input type="hidden" value="n4" name="n4">
</form>
</body>
</html>
  • 1

    I don’t understand the question. When you type what?

  • Their Hidden fields are not serving any purpose. They will not magically pick up existing notes. To make it easy, the form also has to be in PHP (which would help you have a form just for two situations).

1 answer

0

I don’t see why use two forms for the same function, just return the header('Location');.

   $med = (($n1+$n2+$n3+$n4)/4);

     if($med>=7){
        echo("aprovado com ". $med);
     }else if($med<7){
        header('location: q6formdir.php');

     $k= $_POST['n5'];

     if(isset($_POST['salvar'])){
        $mednova = (($med + $k)/2);
     if($mednova>=5){
     echo("aprovado em exame com ".$mednova);
     }else{
    echo("Reprovado, Faça outro teste!");
    header('Location: exame.php');
   //retorna ao formulario;
    }
   }
 }

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.