I added the field max
in the <input>
that it enters the value with the value it has with account (you change the name of the fields that are necessary), which will limit up to the amount it has in account, in the update you make a reconfirmation if the values are in agreement before executing the update.
<?php
$result_usuario = "SELECT * FROM `usuarios` WHERE id=1";
$mostra_dados = mysqli_query($conn, $result_usuario);
while($rows_cursos = mysqli_fetch_assoc($mostra_dados)){
$dinheiroEmConta=$rows_cursos['dinheiro'];
?>
<option value="<?php echo $rows_cursos['id']; ?>"><?php echo $rows_cursos['usuario']; ?></option>
</select>
<input type="text" name="valor" max="<?php echo $dinheiroEmConta; ?>">
<?php
}
?>
This section should come dps from the part where the SELECT
that generates the $result_usuario
, so you can create the variable $dinheiroEmConta
which I added to the code block above, and then do this:
if((isset($_POST['dinheiro']))&&(!empty($_POST['dinheiro']))){
$id = $_POST['id'];
$dinheiro = $_POST['dinheiro'];
if($dinheiro <= $dinheiroEmConta){
$_SESSION['id'] = $id;
$_SESSION['dinheiro'] = $dinheiro;
$recebe_dados = "UPDATE usuarios SET dinheiro = dinheiro -'$dinheiro', depositado = depositado +'$dinheiro' WHERE id = '". $_SESSION['usuarioId'] ."'";
$result_usuario = "UPDATE usuarios SET dinheiro = dinheiro +'$dinheiro' WHERE id = $id";
}
}
puts what you’ve tried there
– Wees Smith
Post updated it is so at the moment
– mateus silva
It’s still a little fuzzy, where you want to set that limit?
– Wees Smith
Fine, then he sends the value to that same page that will make the deposit, that code is where?
– Wees Smith
I want to put the limit when he send for example he has 100 real in his wallet when he type in the field to deposit for example 500 real he will not get understood?
– mateus silva
when he presses the button to send the amount at the moment it is being redirected to the page Setting that makes the update taking the amount typed from his wallet and adding to the bank. $received_data = "UPDATE usuarios SET money = money -'$money' WHERE id = '". $_SESSION['usuarioId'] ." '"; $result_usuario = "UPDATE usuarios SET money = money +'$money' WHERE id = $id";
– mateus silva