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

时间:2016-07-05 18:04:11

标签: javascript php mysql

首先,我在MySQL DATABASE字段中输入两个字段,COIN和字段COIN_CHARGE这里是屏幕截图 POPUP Screnshot, 我希望系统检查用户是否单击是,即尝试登顶并继续,让系统检查他的数据库 Database screen shot并启动此参数,(如果字段-coin-小于字段-coin_charge-)应弹出一个窗口,如果硬币字段大于coin_charge,则不足以继续充值您的帐户字段让系统从硬币中减去coin_charge,即如果(coin = 100)和(coin_charge = 50)硬币将变为50

----------------- POP UP MESSAGE --------------------------- ---

<!-- 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'];
    }
?>

1 个答案:

答案 0 :(得分:0)

$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;
}