我想从字段(B)币值中减去字段(A) - coin_charge值,并将结果存储在字段(B)币中


I want to subtract field (A) - coin_charge value from field (B) coin value and store the result in field (B) coin

首先,我在MySQL数据库字段中得到了两个字段,COIN和字段COIN_CHARGE这里是屏幕截图弹出Screnshot,我希望系统检查用户是否单击YES,即试图顶峰并继续进行,让系统检查他的数据库数据库屏幕截图并开始这个参数,(如果字段-coin-小于字段-coin_charge-)应该弹出一个窗口说,资金不足,无法继续充值您的帐户,否则,如果硬币字段大于coin_charge字段,让系统从硬币中减去coin_charge,也就是说,如果(coin = 100)和(coin_charge =50)硬币将变成50

----------------- 弹出消息 ------------------------------

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Report Assignment</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Report Assignment Now!</h4>
      </div>
      <div class="modal-body">
        <p>You Will Be Charge From Your Portal Account, Do You Wish To Continuo?</p>
      </div>
      <div class="modal-footer">
      <a class="btn btn-primary" data-toggle="modal" onClick="$('#createFormId').modal('show')" >YES</a>
        <button type="button" class="btn btn-default" data-dismiss="modal">NO</button>
      </div>
    </div>
  </div>
</div>

--------------------------- 计算代码 ---------------------------

<?php
    $message_query = mysql_query("select * from student ")or die(mysql_error());
?>
<?php
    while ($row = mysql_fetch_assoc($results)) {
        echo $row['coin'] = $row['coin'] - $row['coin_charge'];
    }
?>
$mysqli = new mysqli("localhost", "username", "password", "dbname");
$userid = $_POST["userid"];
$stmt = $mysqli->prepare('SELECT * FROM student WHERE id = ?');
$stmt->bind_param('i', $userid);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$stmt->close();
$total = $row['coin'] - $row['coin_charge'];
if($total > 0){
    $stmt = $mysqli->prepare("update student set coin = ? where id = ?");
    $stmt->bind_param("ii", $total, $userid);
    $stmt->execute();
    $stmt->close();
    echo $total;
}else{
    echo 'Insufficient Fund to proceed Top Up your account';exit;
}