更新功能不会更新我的INT行

时间:2019-01-21 10:30:13

标签: php sql sql-update

我正在尝试更新数据,但不会正确更新。它将其设置为0。其他字段正在完美更新,但是由于某些原因,只有“ dagprijs”行未更新为该字段中的内容

我的更新代码:

<?php
    if (isset($_POST["Edit"])) {
       global $db;
       $kenteken = htmlspecialchars($_POST["Kenteken"]);
       $merk = htmlspecialchars($_POST["Merk"]);
       $type = htmlspecialchars($_POST["Type"]);
       $soort = htmlspecialchars($_POST["Soort"]);
       $omschrijving = htmlspecialchars($_POST["Omschrijving"]);
       $gps = htmlspecialchars($_POST["GPS"]);
       $dagprijs = htmlspecialchars($_POST["Dagprijs"]); 

        $sql3 = "UPDATE auto
        SET Kenteken=:kenteken, Merk=:merk, Type=:type, Soort=:soort, Omschrijving=:omschrijving, GPS=:gps, Dagprijs=:dagprijs
        WHERE Kenteken =:kenteken";
        $stmt = $db->prepare($sql3);
        $data = array("kenteken" => $kenteken, "merk" => $merk, "type" => $type, "soort" => $soort, "omschrijving" => $omschrijving, "gps" => $gps, "dagprijs" => $dagprijs);

        try {
            $stmt->execute($data);

        } 
        catch (PDOException $e) {
          echo $e->getMessage();
        }
    } 
?>

表格(模式)

<form method="post">
    <div class="modal fade" id="Pas<?php echo $results['Kenteken']?>" role="dialog">
        <div class="modal-dialog">
        <div class="modal-content">
        <div class="modal-header">
        <h4 class="modal-title">Auto met kenteken: <?php echo " " .$results['Kenteken']?> aanpassen?</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        <div class="modal-body">
        <div class="icon-box">
        </div>
        <label for="exampleInputPassword1">Kenteken.</label>
        <input type="text" class="form-control" name="Kenteken" value="<?php echo $results['Kenteken']; ?>">
        <label for="exampleInputPassword1">Merk</label>
        <input type="text" class="form-control" name="Merk" value="<?php echo $results['Merk']; ?>">
        <label for="exampleInputPassword1">Type</label>
        <input type="text" class="form-control" name="Type" value="<?php echo $results['Type']; ?>">
        <label for="exampleInputPassword1">Soort</label>
        <input type="text" class="form-control" name="Soort" value="<?php echo $results['Soort']; ?>">
        <label for="exampleInputPassword1">Omschrijving</label>
        <input type="text" class="form-control" name="Omschrijving" value="<?php echo $results['Omschrijving']; ?>">
        <label for="exampleInputPassword1">GPS</label>
        <input type="text" class="form-control" name="GPS" value="<?php echo $results['GPS']; ?>">
        <label for="exampleInputPassword1">Dagprijs</label>
        <input type="number" class="form-control" name="Dagrpijs" value="<?php echo $results['Dagprijs']; ?>">
        </div>
        <div class="modal-footer">
        <button type="submit" class="btn btn-default" name="Edit" style="float:left; background-color:orange; color:white;">Wijzigen</button>
        </div>
        </div>
        </div>
    </div>
</form>

The database where you can see it will set it to 0

2 个答案:

答案 0 :(得分:1)

此键入错误,因为您在PHP中使用输入名称,所以将其更改为“ Dagprijs”。

<input type="number" class="form-control" name="Dagrpijs" value="<?php echo $results['Dagprijs']; ?>">

<input type="number" class="form-control" name="Dagprijs" value="<?php echo $results['Dagprijs']; ?>">

答案 1 :(得分:0)

(name =)中有错字

<input type="number" class="form-control" name="Dagrpijs" value="<?php echo $results['Dagprijs']; ?>">

应该是

<input type="number" class="form-control" name="Dagprijs" value="<?php echo $results['Dagprijs']; ?>">