How to make a condition with mysql php number

Asked

Viewed 109 times

1

Hi I’m doing like a virtual bank in one part has to make the deposit, the user has the wallet money for example.

I have 500 real in my wallet

but if I put any value over 500 it deposits into the bank account and I wanted the user to put only the maximum value he has in wallet

Code to send value

<center>
    <select name="id">

<?php
    $result_usuario = "SELECT * FROM `usuarios` WHERE id=1";
    $mostra_dados = mysqli_query($conn, $result_usuario);
    while($rows_cursos = mysqli_fetch_assoc($mostra_dados)){ ?>
   <option value="<?php echo $rows_cursos['id']; ?><?php echo $rows_cursos['usuario']; ?></option>
 <?php } ?>
 </select>

  • puts what you’ve tried there

  • 1

    Post updated it is so at the moment

  • It’s still a little fuzzy, where you want to set that limit?

  • Fine, then he sends the value to that same page that will make the deposit, that code is where?

  • 1

    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?

  • 1

    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";

Show 1 more comment

1 answer

1

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"; 
    }
}
  • 1

    Voce can help me reaffirm the update

  • 1

    $id = $_POST['id']; $money = $_POST['money']; $_SESSION['id'] = $id; $_SESSION['money'] = $money; $received_data = "UPDATE usuarios SET money = money -'$money' WHERE id = '". $_SESSION['usuarioId'] ." '"; $result_usuario = "UPDATE usuarios SET money = money +'$money' WHERE id = $id"; $receiva_data2 = "UPDATE usuarios SET deposited = deposited +'$money' WHERE id = '". $_SESSION['usuarioId'] ."'";

  • 1

    Help me please I still haven’t gotten ta getting negative yet

  • I help, but I need some information

  • WHAT ? helps me pf

  • I think now you can, anything you tell me, I may take a little while, but I’ll answer

  • 1

    Man I couldn’t honestly look

  • 1

    Part of sending looks like this <? php $result_usuario = "SELECT * FROM usuarios WHERE id=1";&#xA; $mostra_dados = mysqli_query($conn, $result_usuario);&#xA; while($rows_cursos = mysqli_fetch_assoc($mostra_dados)){ &#xA; $dinheiroEmConta=$rows_cursos['dinheiro'];&#xA;? > <option value="<? php echo $rows_courses['id']; ? >"><? php echo $rows_courses['user']; ? ></option> </select> <input type="text" name="money" max="<? php echo $moneyEmConta; ? >"> <?php } ?>

  • 1

    no update thus $result_usuario = "SELECT money FROM usuarios WHERE id='". $_SESSION['usuarioId'] ." '"; if((isset($_POST['money']))&&(!Empty($_POST['money'])){ $id = $_POST['id']; $money = $_POST['money']; if($money <= $moneyEmConta){ $_SESSION['id'] = $id; $_SESSION['money'] = $money; $receie_data = "UPDATE users SET money = money -'$money',' deposited = deposited +'$money' where id = '". $_SESSION['usuarioId'] ." '"; $result_usuario = "UPDATE usuarios SET money = money +'$money' WHERE id = $id";;}

  • 1

    now it neither decreases the entered value nor increases the value for the bank

  • accuses some error at least?

  • 1

    does not look like this the folder Settings that does update link , and the input part ;link

  • It’s very confusing, has query q doesn’t even exist, like SELECT usuarios SET dinheiro

  • how can you help me?

Show 9 more comments

Browser other questions tagged

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