Problems recording and solving the calculation

Asked

Viewed 31 times

0

I am unable to record the value typed in input and then solve 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>
  • Save where? In database? Which calculation?

  • display the results in an HTML page.

  • calculation of body capacity.

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 divide.

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

So you can take the values and calculate normally.

Follow the code set, I did it in my 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>

0

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

If you’re making a division you should use / and not \ then I would be $adpo = $peso/$alt2;

  • Now the ECHO command is displaying the names Like this: $name""$height""$weight""$age""$adpo;. instead of entering the values of the variables.

  • Check this reply from @brnTwp https://answall.com/a/294650/79646

Browser other questions tagged

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