php code if does not run only Else

Asked

Viewed 42 times

-4

<form method="GET">
    salário: <input type="number" name="salario"> <br>
    tempo de serviço (em meses): <input type="number" name="tds"> <br>
    n° reclamações: <input type="number" name="rec"> <br>
    <input type="submit" name="calcular">
</form>
<?php
if (!empty($_GET["salario"]) && !empty($_GET["tds"]) && !empty($_GET["rec"])) {

    $salario=$_GET["salario"];
    $tds=$_GET["tds"];
    $rec=$_GET["rec"];

    $nsal=($salario*0.2);

    if (($salario > 1000) && ($tds > 12) && ($rec == 0)) {

        echo "Você foi promovido, parabéns.";
        echo "E ganhou um aumento de salário. Seu novo salário é: $nsal";

    } else{
        echo "Sem novidades, volte depois.";
    }
 } 

?>
  • Which values you are passing via the URL parameter?

  • I don’t understand your question

  • What values of variables $salario, $tds and $rec?

  • I’m taking them from an input, which the user himself puts

1 answer

0


The problem is that you are using the empty() to the rec, if the value is 0, PHP considers empty. Change the empty() for isset() that will work.

Take the example:

if (isset($_GET["salario"]) && isset($_GET["tds"]) && isset($_GET["rec"])) {
  // lógica aqui
}

I hope I’ve helped.

  • Thank you very much <3

Browser other questions tagged

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