Page not printing the results

Asked

Viewed 63 times

-1

I am creating a table with a cell in the form of input text to enter a number, and the rest of the cells will be printed after the operations to determine their value.

After the table there is a Submit button to send the input text value to the variable that will start the calculations.

Turns out I’m having trouble printing the results.

<form method="POST" action="meixautonomo.php">
<table border="1">
    <tr>
        <td class="indicador">Informações Gerais</td>
        <td class="indicador">Autonômo</td>
        <td class="indicador">MEI/ME</td>
        <td class="indicador">% de Econômia</td>
    </tr>
    <tr>
        <td>Bônus Bruto</td>
        <td><input type="text" name="entrada"></td>
        <?php
            if(isset($_POST['calcular'])){
                $autonomoBonusBruto = $_POST['entrada'];
                $meimeBonusBruto = $autonomoBonusBruto;
                $porcEconomiaBonusBruto = ($autonomoBonusBruto - $meimeBonusBruto) / $autonomoBonusBruto;
                $autonomoTaxa = 3;
                $meimeTaxa = 3.99;
                $porcEconomiaTaxa = ($autonomoTaxa - $meimeTaxa) / $autonomoTaxa;
                $autonomoINSS;
                if($autonomoTaxa + $meimeTaxa > 5189.82){
                    $autonomoINSS = 570.88;
                }
                else{
                    $autonomoINSS = ($autonomoBonusBruto - $autonomoTaxa) * 0.11;
                }
                $meimeINSS;
                if($meimeBonusBruto <= 5000){
                    $meimeINSS = 44;
                }
                else if($meimeBonusBruto > 5189.82){
                    $meimeINSS = 570.88; 
                }
                else{
                    $meimeINSS = $meimeBonusBruto * 0.11;
                }
                $porcEconomiaINSS = ($autonomoINSS - $meimeINSS) / $autonomoINSS;
                $autonomoIRRF = 2864.91 * 0.15 - 354.80;
                $meimeIRRF;
                if($meimeBonusBruto <= 5000){
                    $meimeIRRF = 21033.22 * 0 - 0 / 12;
                }
                else{
                    $meimeIRRF = $meimeBonusBruto * 0.06;
                }
                $porcEconomiaIRRF = ($autonomoIRRF - $meimeIRRF) / $autonomoIRRF;
                $autonomoISS = $autonomoBonusBruto * 0.05;
                $meimeISS;
                if($meimeBonusBruto <= 5000){
                    $meimeISS = 5; 
                }
                else{
                    $meimeISS = $meimeBonusBruto * 0.05;
                }
                $porcEconomiaISS = ($autonomoISS - $meimeISS) / $autonomoISS;
                $autonomoBonusLiquido = $autonomoBonusBruto - $autonomoTaxa - $autonomoINSS - $autonomoIRRF - $autonomoISS;
                $meimeBonusLiquido = $meimeBonusBruto - $meimeTaxa - $meimeINSS - $meimeIRRF - $meimeISS;
                $porcEconomiaBonusLiquido = ($autonomoBonusLiquido - $meimeBonusLiquido) / $autonomoBonusLiquido;
                $meimeLucro = $meimeBonusLiquido - $autonomoBonusLiquido;
        ?>          
        <td><?php echo $meimeBonusBruto;?></td>
        <td><?php echo $porcEconomiaBonusBruto;?></td>
    </tr>
    <tr>
        <td>Taxa DOC/Boleto</td>
        <td><?php echo $autonomoTaxa;?></td>
        <td><?php echo $meimeTaxa;?></td>
        <td><?php echo $porcEconomiaTaxa;?></td>
    </tr>
    <tr>
        <td>INSS</td>
        <td><?php echo $autonomoINSS;?></td>
        <td><?php echo $meimeINSS;?></td>
        <td><?php echo $porcEconomiaINSS;?></td>
    </tr>
    <tr>
        <td>IRRF</td>
        <td><?php echo $autonomoIRRF;?></td>
        <td><?php echo $meimeIRRF;?></td>
        <td><?php echo $porcEconomiaIRRF;?></td>
    </tr>
    <tr>
        <td>ISS</td>
        <td><?php echo $autonomoISS;?></td>
        <td><?php echo $meimeISS;?></td>
        <td><?php echo $porcEconomiaISS;?></td>
    </tr>
    <tr>
        <td>Bônus Líquido</td>
        <td><?php echo $autonomoBonusLiquido;?></td>
        <td><?php echo $meimeBonusLiquido;?></td>
        <td><?php echo $porcEconomiaBonusLiquido;?></td>
    </tr>
</table>
<?php echo $meimeLucro;}?>
<br>
<input type="submit" name="calcular" value="Gerar resultados">
</form>
  • Error appears ?

3 answers

2

It is not very clear what you ask, but at first, looking superficially we perceive basic mistakes.

Below, I will quote the most visible. But it doesn’t necessarily mean that they are the cause of the problem, however I suspect that at least 1 or 2 of these errors are causing the problem. So I recommend you correct them

PHP: Simple quotes to print variables

Example:

<?php echo '$porcEconomiaBonusBruto';?>
<?php echo '$meimeBonusBruto';?>

This will print literally due to the single Quotes. It will be written literally:

$porcEconomiaBonusBruto
$meimeBonusBruto

A variable does not need to be bounded by quotation marks.

Fix it that way:

<?php echo $porcEconomiaBonusBruto;?>
<?php echo $meimeBonusBruto;?>

HTML: Spaces in attribute assigners and XML markup

Example:

<input type = "submit" name = "calcular" value = "Gerar resultados"/>

No need to have spaces in the assigners. Correction:

<input type="submit" name="calcular" value="Gerar resultados">

The bar at the end I also removed. This you use if the DTD is XHTML.

HTML: Syntax error (tag table)

One problem that can be severe is the lack of the tag closure character <table

<table border = "1"
    <tr>

The > to close. Correction:

<table border="1">
    <tr>

Maybe that’s where you’re holding the results. But if you press CTRL+U (Chrome), you can see the codes.

HTML: The form is no action

<form method = "POST">

Example of how it should be:

<form method="POST" action="pagina.php">

There where is "page.php", obviously it is an EXAMPLE. You should put the page that will receive the data.

Other

Just note, the stretch in PHP with this mountain of null variables, does not make any sense.

Nor does the expression that $porcEconomiaBonusBruto receives as it always results in ZERO.

Basically, what you’re doing is assigning $_POST['entrada'] for a variable $autonomoBonusBruto which is used to assign value to another variable $meimeBonusBruto. Finally,

$porcEconomiaBonusBruto = ($autonomoBonusBruto - $meimeBonusBruto) / $autonomoBonusBruto;

It’s the same as doing ($_POST['entrada'] - $_POST['entrada']) / $_POST['entrada'].

I do not know what you mean by this, so I abstain from prolonging this matter, but I thought it appropriate to comment.

  • I fixed everything you said but still did not give, the action of a refresh on the page, this ends up making the value of variables back to null, no ?

  • No. When you leave without the action you are posted to the page itself. If you have not shown the calculation, you are still doing something wrong. Just remove the quotation marks from the variables $meimeBonusBruto and $porcEconomiaBonusBruto as commented in the reply.

  • I removed it a long time ago I will edit to you to see how the code is now, more complete.

  • and is to be displayed the data on the same page

2

Read the comments next to the variables.

If no action exists the form is submitted to the same page.

<form method = "POST">
<table border = "1">
    <tr>
        <td class = "indicador">Informações Gerais</td>
        <td class = "indicador">Autonômo</td>
        <td class = "indicador">MEI/ME</td>
        <td class = "indicador">% de Econômia</td>
    </tr>
    <tr>
        <td>Bônus Bruto</td>
        <td><input type = "text" name = "entrada" id="entrada" /></td>
        <?php 
        if(isset($_POST['calcular']))
        {
            $autonomoBonusBruto = $_POST['entrada'];
            $autonomoTaxa = 3;
            $autonomoINSS    =1;      // VARIÁVEL = NULL SE NÃO TIVER VALOR DEFINIDO, divisão por zero não existe
            $autonomoIRRF;           // variável não sendo utilizada
            $autonomoISS;               // variável não sendo utilizada
            $autonomoBonusLiquido;  // variável não sendo utilizada
            $meimeBonusBruto = $autonomoBonusBruto;
            $meimeTaxa = 3.99;
            $meimeINSS    =0;            // VARIÁVEL = NULL SE NÃO TIVER VALOR DEFINIDO
            $meimeIRRF;                // variável não sendo utilizada
            $meimeISS;                // variável não sendo utilizada
            $meimeBonusLiquido;        // variável não sendo utilizada

            $porcEconomiaBonusBruto = ($autonomoBonusBruto - $meimeBonusBruto) / $autonomoBonusBruto;
            $porcEconomiaTaxa = ($autonomoTaxa - $meimeTaxa) / $autonomoTaxa;
            $porcEconomiaINSS = ($autonomoINSS - $meimeINSS) / $autonomoINSS;
            $porcEconomiaIRRF;     // variável não sendo utilizada
            $porcEconomiaISS;     // variável não sendo utilizada
            $porcEconomiaBonusLiquido;     // variável não sendo utilizada

            echo '<td>'.$meimeBonusBruto.'</td>';
            echo '<td>'.$porcEconomiaBonusBruto.'</td>';
        }
        else
        {
            echo '<td></td>
                  <td></td>';
        }
        ?>          

    </tr>
</table>
<br/>
<input type = "submit" name = "calcular" value = "Gerar resultados"/>
</form>


<script>
window.onload=function(){ document.getElementById('entrada').focus(); }
</script>

0

  • Assign values to variables $autonomoINSS and $meimeINSS for the calculation cannot be done with null values.
  • Remove quotes when printing variable values.

Browser other questions tagged

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