Salary form in php

Asked

Viewed 150 times

-1

I have problems with my code, fill out the form using the POST method but my php doesn’t print right, I’ve done a desktop test and it worked, but whenever I use the POST method the page does not find the correct variable.

<html>


    <title>Avaliacao 1</title>
  </head>
  <body>
    <h4 class="display-4 text-center">Avaliacao 1</h4>
    </hr>
<div class="col-12 text-center mt-5">
      <h4 class="display-4">Execicio 2</h4>

  </div>

    <form action="ex2.php" method="POST">
  <div class="form">
     <div class="form-group col-md-6">
      <label for="inputname"><h7>Nome:</h7></label>
      <input type="text" class="form-control" name="nome" placeholder="Digite o seu Nome...">
    </div>
    <div class="form-group col-md-6">
      <label for="inputname"><h7>Categoria:</h7></label>
      <input type="text" class="form-control" name="categoria" placeholder="Digite a categoria...">
    </div>
    <div class="form-group col-md-6">
      <label for="inputname"><h7>Salario:</h7></label>
      <input type="text" class="form-control" name="salario" placeholder="Digite Salario...">
    </div>

    <br>

  <button type="submit" class="btn btn-primary" >Enviar</button>
    <button type="reset" class="btn btn-warning">Limpar</button>

  <hr>

  </body>
</html>

Filing cabinet: ex2.php:

    <?php
    $nome=$_POST['nome'];
    $categoria=$_POST['categoria'];
    $salario=$_POST['salario'];
    $porc1=$salario*0.3;
    $porc2=$salario*0.5;


    if ($categoria=="a"||$categoria=="c"){
        $salarioA=$salario+$porc1;
        $porc=" 30%";

    }elseif ($categoria=="b"||$categoria=="d"){
        $salarioA=$salario+$porc2;
        $porc=" 50%";
    }
    echo "Nome: $nome";
    echo "</br>";
    echo "Categoria: $categoria";
    echo "</br>";
    echo "salário Atual: $salario ";
    echo "</br>";
    echo "Porcentagem de Aumento: $porc";
    echo "</br>";
    echo "Salario C/ aumento: $salarioA";
    var_dump($_POST);

    ?>





1 answer

0


Try this code: https://repl.it/@TaffarelXavier/WoozyAgedFeeds

 <?php

if($_SERVER['REQUEST_METHOD']=='POST'){
 $nome=$_POST['nome'];
    $categoria=$_POST['categoria'];
    $salario=$_POST['salario'];
    $porc1=$salario*0.3;
    $porc2=$salario*0.5;


    if ($categoria=="a"||$categoria=="c"){
        $salarioA=$salario+$porc1;
        $porc=" 30%";

    }elseif ($categoria=="b"||$categoria=="d"){
        $salarioA=$salario+$porc2;
        $porc=" 50%";
    }
    echo "Nome: $nome";
    echo "</br>";
    echo "Categoria: $categoria";
    echo "</br>";
    echo "salário Atual: $salario ";
    echo "</br>";
    echo "Porcentagem de Aumento: $porc";
    echo "</br>";
    echo "Salario C/ aumento: $salarioA";
    var_dump($_POST);
}


    ?>

Browser other questions tagged

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