Problems in recording and resolution of the calculation

0

I am not able to write the value entered in input and then resolve the calculation.

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
</head>

<body>
    <form method="post">
        <label for="GET-name">Nome:</label>
        <input type ="text" name="nome"/><br>
        <label for="GET-name">Altura:</label>
        <input type ="text" name="altura"/><br>
        <label for="GET-name">Peso  :</label>
        <input type ="text" name="peso"/><br>
        <label for="GET-name">Idade:</label>
        <input type ="text" name="idade"/><br>
        <input type = "submit" value="calcular">
    </form>
    <?php
    $nome =$_post['nome'];
    $altura= $_post['altura'];
    $peso=$_post['peso'];
    $idade=$_post['idade'];
    $alt2 = $altura*$altura;
    $adpo = $peso\$alt2;

    ECHO $nome."<br>".$altura."<br>".$peso."<br>".$idade."<br>".$adpo;


    ?>

    </body>
</html>
    
asked by anonymous 27.04.2018 / 20:59

2 answers

1

First, there are some syntax errors in your code, in the first case:

Para pegar os values dos campos input via POST, o código não se escreve "$_post" e sim "$_POST" (tudo maiúsculo) como por exemplo:
$nome =$_POST['nome'];

Then in the calculation, you used "\" instead of "/" to split.

Código certo:
$adpo = $peso/$alt2; o código aqui

So you can get the values and calculate normally.

Here is the code that I set, I did it in the head, but I think it will work:

    <!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
</head>

<body>
<form method="post">
<label for="GET-name">Nome:</label>
<input type ="text" name="nome"/><br>
<label for="GET-name">Altura:</label>
<input type ="text" name="altura"/><br>
<label for="GET-name">Peso  :</label>
<input type ="text" name="peso"/><br>
<label for="GET-name">Idade:</label>
<input type ="text" name="idade"/><br>
<input type = "submit" value="calcular">
</form>
<?php

$nome =$_POST['nome'];

$altura= $_POST['altura'];

$peso=$_POST['peso'];

$idade=$_POST['idade'];

$alt2 = $altura*$altura;
$adpo = $peso/$alt2;

ECHO $nome."<br>".$altura."<br>".$peso."<br>".$idade."<br>".$adpo;

?>


</body>
        </html>
    
27.04.2018 / 21:14
0

I think the problem is here $adpo = $peso\$alt2; .

If you are doing a split you should use / and not \ then you would get $adpo = $peso/$alt2;

    
27.04.2018 / 21:13