无法使用php保存表列中的更新行

时间:2016-11-13 11:38:06

标签: javascript php

我很难在PHP中的UPDATE SET语句中保存我的记录。我使用JavaScript来更新提交记录。见下面的代码:

/* Update Record  */
$(document).on('submit', '#emp-UpdateForm', function() {

   $.post("update.php", $(this).serialize())
    .done(function(data){
        $("#dis").fadeOut();
        $("#dis").fadeIn('slow', function(){
             $("#dis").html('<div class="alert alert-info">'+data+'</div>');
             $("#emp-UpdateForm")[0].reset();
             $("body").fadeOut('slow', function()
             {
                $("body").fadeOut('slow');
                window.location.href="home.php";
             });                 
         });    
    });   
    return false;
});
/* Update Record  */

请注意,上述方法是检索UPDATE SET语句所在的文件update.php。见代码:

if(isset($_POST)){

$stmt = $update->runQuery("UPDATE IndividualProduct SET name=:name,model=:model,manufacturer=:manufacturer,productionYear=:productionYear,color=:color,purchaseAmount=:purchaseAmount WHERE id_product=:id");

$stmt->bindparam(":name",$pname);
$stmt->bindparam(":model",$pmodel);
$stmt->bindparam(":manufacturer",$pmanuf);
$stmt->bindparam(":productionYear",$pyear);
$stmt->bindparam(":color",$pcolor);
$stmt->bindparam(":purchaseAmount",$pamount);
$stmt->bindparam(":id",$id);

$id         = $_POST['id_product'];
$pmanuf     = $_POST['pmanuf'];
$pname      = $_POST['pname'];
$pmodel     = $_POST['pmodel'];
$pyear      = $_POST['pyear'];
$pcolor     = $_POST['pcolor'];
$pamount    = $_POST['pamount'];

$stmt->execute();}

这是edit_form.php,其中编辑时检索列中的记录:

<form method='post' id='emp-UpdateForm' action='#'>

<table class='table table-bordered'>
    <input type='hidden' name='id' value='<?php echo $row['id_product']; ?>' />
    <tr>
        <td>Mærke</td>
        <td><input type='text' name='manufacturer' class='form-control' value='<?php echo $row['manufacturer']; ?>' required></td>
    </tr>

    <tr>
        <td>Navn</td>
        <td><input type='text' name='name' class='form-control' value='<?php echo $row['name']; ?>' required></td>
    </tr>

    <tr>
        <td>Model</td>
        <td><input type='text' name='model' class='form-control' value='<?php echo $row['model']; ?>' required></td>
    </tr>

    <tr>
        <td>Årgang</td>
        <td><input type='text' name='productionYear' class='form-control' value='<?php echo $row['productionYear']; ?>' required></td>
    </tr>

    <tr>
        <td>Pris</td>
        <td><input type='text' name='purchaseAmount' class='form-control' value='<?php echo $row['purchaseAmount']; ?>' required></td>
    </tr>

    <tr>
        <td>Farve</td>
        <td><input type='text' name='color' class='form-control' value='<?php echo $row['color']; ?>' required></td>
    </tr>

    <tr>
        <td colspan="2">
        <button type="submit" class="btn btn-primary" name="btn-update" id="btn-update">
        <span class="glyphicon glyphicon-plus"></span> Save Updates
        </button>
        </td>
    </tr>

</table>

当我输入另一个像&#34; Acer&#34;连续,例如在&#34;制造商&#34;行的值=&#34;华硕&#34;然后点击提交(保存更新),价值变回&#34;华硕&#34;并且没有更新到我的输入。

0 个答案:

没有答案