dongqing220586 2018-06-09 19:56
浏览 54

phpmyadmin数据库表未更新

I am using php, Ajax, and MySQL. When I submit the form data is not updated in the database table. I am badly stuck here. Can anyone please advice me that how can I solve this problem?? Thanks in advance guys. codes are given below :

update_details.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>

modify_func.php

    <?php
$con=mysqli_connect("localhost","root","","forestdb");
if(isset($_POST['dependence_of_local_people'])){
    $plantation_journal_no=$_GET['id'];
    $dependence_of_local_people=$_POST['dependence_of_local_people'];
    $wage_income=$_POST['wage_income'];
    $sql="UPDATE `benefits_derived` SET `dependence_of_local_people`='$dependence_of_local_people',`wage_income`='$wage_income' WHERE `plantation_journal_no`='$plantation_journal_no'";

    $result=mysqli_query($con,$sql);
}
?>
  • 写回答

1条回答 默认 最新

  • dongyun4010 2018-06-10 21:58
    关注

    I think by using $_GET['id']; you are trying to get some url parameter which is present in the url where form is displayed but you are using jquery to submit your form so $plantation_journal_no=$_GET['id']; wont work in your code as $_GET['id'] is not set.

    Try this:

    $('.btn-submit6').click(function(e) {
            e.preventDefault();
            $.ajax({
                url:"modify_func.php",
                method:"POST",
                data:$('#form6').serialize() + '&id=<?php echo $_GET['id']; ?>',
                success:function(data)
                {
                    document.getElementById("form6").reset();
                }
            });
        });
    

    than in your modify_func.php use this:

    $plantation_journal_no=$_POST['id'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析