0
I’d like to redeem the value of one input
with echo
of loop of a while
and request UPDATE redeeming that amount.
<form method="POST" name="form" action="<?php echo $_SERVER['PHP_SELF'];?>">
<?php while ($linhasMotoristas = mysqli_fetch_array($consultaMotoristas)) {
$motoristasStatus = $linhasMotoristas['status'];
$motoristasId = $linhasMotoristas['idmotoristas'];
$motoristasNome = $linhasMotoristas['nome'];
$motoristasCpf = $linhasMotoristas['cpf'];
$motoristasGanhos = $linhasMotoristas['ganhos']
?>
<tr>
<td class="s">
<?php
if($motoristasStatus == 1){
echo "<div style='color: green;'>●</div>";
}else{
echo "<div style='color: red;'>●</div>";
}
?>
</td>
<td class="m"><?php echo $motoristasId;?></td>
<td class="n"><?php echo $motoristasNome;?></td>
<td class="c"><input type="hidden" name="td_1" value="<?php echo $motoristasId;?>"><?php echo $motoristasCpf;?>
</td>
<td class="g"><?php echo round($motoristasGanhos, 2);?></td>
<td>
<?php
if (isset($_POST['submit'])?$_POST['submit'] : 0) {
$cpfMotorista = $_POST['td_1'];
$valorBruto = $_POST['valorBruto'];
$porcentagemBase = 5/100;
$EncargosBase = 25/100;
$vezesPorcentagem = $valorBruto*$porcentagemBase;
$menosEncargosBase = $vezesPorcentagem-$EncargosBase;
$resultadoLiquido = $menosEncargosBase*$porcentagemBase;
$resultadoGeral = $resultadoLiquido;
$inserirBanco = "UPDATE getmoney.motoristas SET ganhos = COALESCE(ganhos, 0) + '$resultadoGeral' WHERE idmotoristas = '$cpfMotorista'";
$execInserirBanco = mysqli_query($conexao,$inserirBanco);
}
?>
<input type="text" name="valorBruto">
<input type="submit" name="submit" value="Calcular">
<?php echo $cpfMotorista;?>
<?php echo round($resultadoGeral,2); ?>
</td>
</tr>
<?php } ?>
</form>
In this picture, as you can see, it only rescues the ID 25 and I wanted you, according to the line, to rescue the ID user and made the UPDATE of the sum in the field input
summed...
I didn’t understand anything. Clarify your doubt.
– user60252
<td class="c"><input type="Hidden" name="td_1" value="<? php echo $motoristasId;? >"><? php echo $motoristasCpf;? > </td>
– Maykel Figueiredo
Would you like to redeem this loop value in "value="<? php echo $motoristasId;? >" and when using calculate when you can see in the image, update only in the requested ID
– Maykel Figueiredo
I don’t understand your code, for me it doesn’t make sense what it does. Inside while rescues form values and update. Your query returns how many different records?
– user60252
If the answer solved your problem mark it as accepted, see https://i.stack.Imgur.com/jx7Ts.png and why https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-accepta reply/1079#1079
– user60252