3
I have a form that gives me the result on another page, but I would like the result to appear on the same page.
<form name="calc" method="get" enctype="multipart/form-data" action="resultado.php"> <input type="text" id="Peso" name="peso" required="">
<input type="text" id="Altura" name="altura" required="">
<input type="text" id="Peso" name="peso" required="">
<input type="submit" class="button-green" value="CALCULAR">
</form>
php result.
<div id="resultado">
<?php
$peso = $_GET['peso'];
$altura = $_GET['altura'];
$conta1 = $altura*$altura;
$conta2 = $peso/$conta1;
$resultado = number_format($conta2);
if(isset($resultado) && $resultado != '0'){;
echo '<h1>Seu IMC é:</h1>';
echo '<h2>'.$resultado.'</h2>';
}else{
echo '<h1>Por favor, utilize apenas numeros!</h1>';
}
?>
</div>
:Look how the
method
of your form. Remember to validate if something comes in the request, if not when accessing the first time it generates a Warning of Undefined index: x. Otherwise this is it :) +1– rray
hehe Yes, I was seeing this after I read your reply... I will edit here worth +1
– gustavox
thanks friend worked out :)
– kaiquemix
have another question to put if with radio button we can go chat?
– kaiquemix
So @kaiquemix, you better come up with another question. Sopt works as a repository of questions about programming, and was designed to help other users who have the same questions. But don’t be shy, you can ask as many questions as you want, as long as they’re objective, well formatted, etc... the way you did this. :)
– gustavox
i am trying to do something like this: if (isset($result) < 17) { echo 'is less than 17'; } but nothing appears..
– kaiquemix
It is difficult to answer in comment, the best is to create another question, but try
if (isset($resultado) && $resultado < 17) { echo 'é menor que 17'; }
...– gustavox
@gustavox as do for the result tbm be broken number because I can put 1.80 and 50.0 and the result only appears integer
– kaiquemix
So that’s practically another question... Anyway, I talked about it in the answer (take a look at the code)... You set the parameters of
number format
? The variable$resultado
is like this:$resultado = number_format($conta2, 2, ".", ",");
? Important detail: At the entrance (in the fieldinput
) has to be with.
and not with,
...– gustavox
ta thus: $result = number_format($conta2);
– kaiquemix
So, but it has to be like this:
$resultado = number_format($conta2, 2, ".", ",");
.– gustavox
I put thank you :)
– kaiquemix