I added the max
field to <input>
that it types the value with the value that it has with account (you change the name of the fields that are needed), which will limit to the amount that it takes into account, in the update you do a reconfirmation if the values are in agreement before running 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 excerpt should come from the part where SELECT
that generates $result_usuario
occurs, so you can create the $dinheiroEmConta
variable that I added in the above code block, 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";
}
}