表单字段数据的实时计算未插入数据库

时间:2018-07-03 06:20:04

标签: javascript php html database

我有一些表格字段。某些表单字段数据已禁用。表单字段就像实时计算一样。计算很好。即使将其插入数据库,但禁用的表单字段数据也不会插入。我的HTML代码在这里

<form method="POST" oninput="x.value=parseInt(a.value)-parseInt(a.value)*parseInt(b.value)/100;y.value=x.value-parseInt(c.value);x.value=parseInt(x.value);">
<?php
$sql= mysqli_query($con,"SELECT SUM(room_book.price) AS total, room.rn,room.rc,room.tbn,room.rp,room_book.room_number,room_book.bed_book,room_book.rand FROM room INNER JOIN room_book ON room.rn = room_book.room_number WHERE room_book.rand = '$rand'");
while ($row = mysqli_fetch_assoc($sql)) {
        ?>
        <div class="row ">
            <div class="form-group col-md-3">
                <label>Total Price</label>
                 <input value = "<?php echo $row['total']; ?>" id="a" name="price" disabled class="form-control" placeholder="(&#2547;)<?php echo number_format($row['total']); ?>">
            </div>

            <div class="form-group col-md-3">
                <label>Discount In Percentage(%)</label>
                 <input value = "0%" name="prcntg" required id="b" class="form-control" placeholder="0%">
            </div>

        </div>


        <div class="row ">
            <div class="form-group col-md-3">
                <label>Total Payable</label>
                 <input name="x" disabled class="form-control" placeholder="">
            </div>

            <div class="form-group col-md-3">
                <label>Total Paid</label>
                 <input name="paid"  id="c" required class="form-control" placeholder="(&#2547;)<?php echo number_format($row['total']); ?>">
            </div>
        </div>
        <div class="row ">
            <div class="form-group col-md-3">
                <label>Total Due</label>
                 <input name="y" for="c" disabled class="form-control" placeholder="(&#2547;)<?php echo number_format($row['total']); ?>">
            </div>
            <div style="margin-top:24px" class="form-group col-md-3">
                <button name="submit" type="submit" data-loading-text="Loading..." class="btn btn-success"><i class="glyphicon glyphicon-ok-sign"></i> Confirm Invoice</button>
            </div>
        </div>

                    <?php } ?>
        </form>

这些代码运行良好。请参阅屏幕截图

Form field data


我的密码

<?php
   if(isset($_POST['submit'])){
       $price  = $_POST['price'];
       $prcntg = $_POST['prcntg'];
       $x      = $_POST['x'] ;
       $paid   = $_POST['paid'];
       $y      = $_POST['y'] ;
       $sql = mysqli_query($con,"UPDATE `room_book` SET prcntg = '$prcntg', x = '$x', paid = '$paid', due = '$y', status = 'Active'");
       if($sql == true){
            echo "<script> window.open('final.php?final=$rand','_self'); </script>";
       }
?>

Database data


禁用的数据仍为0。如何解决此问题。

3 个答案:

答案 0 :(得分:1)

当您禁用任何HTML元素或对任何HTML元素使用Disabled属性时,它不会提交,您也看不到这些值。名称本身表明该元素已禁用。改为使用“只读”属性。

希望这会有所帮助。

答案 1 :(得分:0)

那是因为您无法获得禁用的输入值。因此,如果可以的话,您应该使用readonly

答案 2 :(得分:0)

已禁用意味着您将忽略返回到控制器的数据,因此它将为null /不存在。您应该使用只读