修改后我的数据库表没有更新

时间:2018-06-10 03:07:49

标签: javascript php jquery mysql ajax

我是PHP的新手。当我尝试更新或修改我的表单时,它不会在phpmyadmin数据库中更新。我正在使用AJAX,jQuery和PHP。我严重困扰她,所以任何人都可以指导我如何解决这个问题。以下是代码人.. update_details.php

let array = [];
let testObj = {
    foo: 1,
  bar: {
    fooFoo: 11,
    fooBar: 22
  }
}

let testObj2 = Object.assign({}, testObj);
testObj2.baz = 3;
testObj2.bar.fooBaz = 33;
array.push(testObj2);

let testObj3 = Object.assign({}, testObj);
testObj3.baz = 4;
testObj3.bar.fooBaz = 44;
array.push(testObj3);

console.log(array)

这是我的modify_func.php

    <form id="form6" name="form6" method="post">
  <div class="row">
    <h4 style="font-size: 16px;padding-left: 15px;"><b>Benefits Delivered by Local People from Plantation Felling:</b></h4><br>
    <div class="col-sm-6">
      <div align="right" style="padding-right: 10px;">
        <label style="font-weight:300;font-size: 15px;margin-top:5px; ">Dependence of Local People on the Site:
        </label>
        <select name="dependence_of_local_people" id="dependence_of_local_people" style="width:30%;height: 30px; margin-left: 10px; border-radius: 5px;margin-top:5px; ">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
        </select><br><br>
      </div>
    </div>
    <div class="col-sm-4">
      <div align="right" style="padding-right: 10px;">
        <label style="font-weight:300;font-size: 15px;">Wage Income:</label>
        <input type="text" name="wage_income" id="wage_income" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
      </div>
    </div>
    <div class="col-sm-2">
      <div align="right" style="padding-right: 0px;">
        <input class="btn btn-info btn-submit6" type="submit" name="submit5" value="Update" onclick="move5()">
      </div>
    </div>
  </div>
</form>
<script>
    jQuery(document).ready(function() {
        $('.btn-submit6').click(function(e) {
            e.preventDefault();
            $.ajax({
                url:"modify_func.php",
                method:"POST",
                data:$('#form6').serialize(),
                success:function(data)
                {
                    document.getElementById("form6").reset();
                }
            });
        });
    });
</script>

3 个答案:

答案 0 :(得分:0)

试试这个

$("#form6").submit(function() {
    $.post("modify_func.php", $("#form6").serialize());
});

答案 1 :(得分:0)

只需更改您的HTML代码

即可
<div align="right" style="padding-right: 0px;">
    <input class="btn btn-info btn-submit6" type="submit" 
     name="submit5" value="Update" onclick="move5()">
</div>

<div align="right" style="padding-right: 0px;">
    <input class="btn btn-info btn-submit6" type="button" 
     name="submit5" value="Update" onclick="move5()">
  </div>

和js:

jQuery(document).ready(function() {
    $('.btn-submit6').click(function() {
        $.ajax({
            url:"modify_func.php",
            method:"POST",
            data:$('#form6').serialize(),
            success:function(data)
            {
                document.getElementById("form6").reset();
            }
        });
    });
});

每次点击提交按钮,打开chrome devtool&gt; network&gt; XHR看看会发生什么。

答案 2 :(得分:0)

首先我不确定是否有必要在数据库列上使用单引号而不是仅在要接收的值中使用:这就是我的意思

UPDATE salary SET salary_id ='$salary' 

其次,如果isset应该收到表单提交按钮名称

相关问题