5
How to put the value of a variable (already calculated in PHP) inside a input?
<form method="post" action="calculos.php">
<div id="circulantes">
<div class="ativocirculante" id="ativocirculante">
<h2>ATIVO CIRCULANTE<input type="text" placeholder="R$ 0,00" id="ac" readonly/></h2>
<h4>Ativo Errático (Financeiro) <input type="text" placeholder="R$ 0,00 aplicações" id="ae"/></h4>
<h4>Disponíveis (Caixa e Bancos)<input type="text" placeholder="R$ 0,00" id="disp"/></h4>
<h3>ACO<input type="text" placeholder="R$ 0,00" id="aco" readonly/></h3>
<h4>Contas a receber<input type="text" placeholder="R$ 0,00" id="cr" name="ncr" value="<?php echo $crTot;?>" readonly/></h4>
<h4 id="cr1">Até 30 dias<input type="text" placeholder="R$ 0,00" id="cr11" name="ncr11"/></h4>
<h4 id="cr2">31 a 60 dias<input type="text" placeholder="R$ 0,00" id="cr22" name="ncr22"/></h4>
<h4 id="cr3">61 a 90 dias<input type="text" placeholder="R$ 0,00" id="cr33" name="ncr33"/></h4>
<h4 id="cr4">Acima de 90 dias<input type="text" placeholder="R$ 0,00" id="cr44" name="ncr44"/></h4>
<h4>Estoque<input type="text" placeholder="R$ 0,00" id="est"/></h4>
<h4>Adiantamento a Fornecedores<input type="text" placeholder="R$ 0,00" id="af"/></h4>
<h4>Despesas antecipadas<input type="text" placeholder="R$ 0,00" id="da"/></h4>
<input type="submit" value="calcular">
</div>
<?php
$crTot = "";
if(isset($_POST)){
$cr1 = $_POST['ncr11'];
$cr2 = $_POST['ncr22'];
$cr3 = $_POST['ncr33'];
$cr4 = $_POST['ncr44'];
$crTot = $cr1+$cr2+$cr3+$cr4;
echo $crTot;
}
But it’s already been done, so what’s the problem?
– Woss
The following message appears inside the input: (<br /><b>Notice</b>: Undefined variable: crTot in <b>C: xampp htdocs menuVertical apCirculantes.php</b> on line <b>24</b><br />)
– Bruce Duarte
This means that the variable ! You set the variable before trying to print ?
– rbz
Add PHP code before form
– rbz
Yes, I believe it is defined in the code below: <?php $crTot = ""; if(isset($_POST)){ $cr1 = $_POST['ncr11']; $cr2 = $_POST['ncr22']; $Cr3 = $_POST['ncr33']; $cr4 = $_POST['ncr44']; $cr1+$cr2+$Cr3+$$cr4; echo $crTot; }
– Bruce Duarte
Put the PHP code before the form, and don’t forget to close: <? php $crTot = ""; if(isset($_POST)){.... } ?>
– rbz
the PHP code is added on a page called "calculos.php" and my action is calling this function.
– Bruce Duarte
Yes but these definitions $cr1 = $_POST['ncr11'], etc have to stay before your form
– rbz
Look at the addition I made
– rbz
Okay, I put it before the form and now the "Undefined variable" message is missing, but she’s not calculating the sum of the others.
– Bruce Duarte
this input (<H4>Accounts receivable<input type="text" placeholder="R$ 0,00" id="cr" name="ncr" value="<?php echo $crTot;?>" readonly/></H4>) should appear within it the value of the sum of the others, correct? If yes, there is some error because it is null...
– Bruce Duarte
There is problem of how it is bringing by the POST. To test you can do so: $cr1 = 1; $cr2 = 2; $Cr3 = 3; $cr4 = 4;
– rbz
It worked Raoni BZ, but why is not rolling with the POST?
– Bruce Duarte
Then it would be a problem of how you are sending and searching with the POST. .
– rbz
Okay! I will. Thank you
– Bruce Duarte
Guys, I’m sorry but I’m a beginner on this site. How do I finish a question?
– Bruce Duarte
I do not know if it is still so, but I never opened questions. https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-accepta reply
– rbz
There’s a " V " below the arrows next to the answer, there’s no ?!
– rbz
OK, finished and created another for the POST.
– Bruce Duarte