使用DECIMAL输入更新输入(php,mysql)

时间:2017-06-07 01:21:02

标签: php

其他更新功能运作良好,但我尝试更新任何数据,支付率的现有值变为0.其他值似乎更新。只有付款率变为0。

下面的

是小数输入的html

    <div class="form-group">
    <label class="control-label col-sm-4" >Payment Rate:</label>
    <div class="col-sm-4">
        <input type="decimal" class="form-control" name="payment" value="<?php echo "RM"; ?> <?php if(isset($row['payment_puspakom'])){ echo $row['payment_puspakom']; } ?>" required placeholder="Enter Payment Rate (RM)">
    </div>
</div>

这是我的更新sql语句。

if(isset($_POST['submit'])){
$id = mysqli_real_escape_string($link, $_POST["puspaid"]);
$vehicle = mysqli_real_escape_string($link,$_POST["vehicle"]);
$date = date("Y-m-d",strtotime($_POST["date"]));
$specification = mysqli_real_escape_string($link,$_POST["specification"]);
$stats = mysqli_real_escape_string($link,$_POST["stats"]);
$next = date("Y-m-d",strtotime($_POST["next"]));
$payment = mysqli_real_escape_string($link,$_POST["payment"]);
$status = mysqli_real_escape_string($link,$_POST["status"]);
$update = mysqli_real_escape_string($link,$_SESSION["idinfostaf"]);

$updpuspa="UPDATE puspakom SET id_fkVehicle='$vehicle', id_fkPuspakomStatus='$stats', date_puspakom='$date', specification='$specification', payment_puspakom='$payment', dateNext_puspakom='$next', status_puspakom='$status', updateby_puspakom='$update' WHERE id_puspakom=".$id;
$respuspa=mysqli_query($link,$updpuspa);
if($respuspa){
  $success = "Record Updated Successfully";
}
else{
  $error = "Error Updating Record. Try Again...".mysqli_error($link);
}
 }

我似乎无法找到我所犯的错误。

1 个答案:

答案 0 :(得分:0)

感谢那些试图回答我的问题的人......已经解决了这个问题。我只是删除echo RM

  <div class="form-group">
<label class="control-label col-sm-4" >Payment Rate:</label>
<div class="col-sm-4">
    <input type="decimal" class="form-control" name="payment" value="<?php if(isset($row['payment_puspakom'])){ echo $row['payment_puspakom']; } ?>" required placeholder="Enter Payment Rate (RM)">
 </div>

该字段设置为十进制(10,2)。将echo RM放在那里,导致rm随小数值一起被携带。这就是更新后价值变为零的原因。