0

I'm trying to program a body mass index calculator, but the code isn't printing the results. I'm using VS Code and it says there is a fatal error in this line: ($_SERVER["REQUEST_METHOD"] == "POST")

Just can't see this "fatal error".

Below I will put the code I'm using and how the calculator appears when running in the browser.

<html>
<head>
<meta charset="utf-8">
   <title>Calculadora de Peso Corporal</title>
</head>
<body>
   <h1>Calculadora de Peso Corporal</h1>
   <form method="post" action="">
       <label for="nome">Seu nome:</label>
       <input type="text" name="nome" required>
       <br>
   <br>
       <label for="peso">Seu peso (em kg):</label>
       <input type="number" step="0.01" name="peso" required>
       <br>
   <br>
      <label for="altura">Sua altura (em cm):</label>
       <input type="number" name="altura" required>
       <br>
   <br>
   <br>
       <a href="Calcular.html"> <input name="Calcular" type="submit" id="Calcular"     value="Calcular"/> </a>
   </form>

<h1>  
 <?php
{  
if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $nome = $_POST["nome"];
   $peso = $_POST["peso"];
   $altura = $_POST["altura"];

   function calcularIMC($peso, $altura) {
       $altura = str_replace(',', '.', $altura);
        $result = $peso/$altura**2;
        return $result;
       $peso = $_POST['peso'];
        $altura = $_POST['altura']; 
}
   }
   $imc_resultado = calcularIMC($peso, $altura);
   echo "<p>Nome: " . $nome . "</p>";
   echo "<p>Peso: " . $peso . " kg</p>";
   echo "<p>Seu IMC é: " . round($imc_resultado, 2) . "</p>";
}
?>
</h1>

</body>
</html>

Code running in browser

Mkenobii
  • 1
  • 1

0 Answers0