моя таблица базы данных не обновляется после изменения - PullRequest
0 голосов
/ 10 июня 2018

Я новичок в PHP.Когда я пытаюсь обновить или изменить мою форму, она не обновляется в базе данных phpmyadmin.Я использую AJAX, JQuery и PHP.Я ее сильно застрял, так что кто-нибудь может подсказать мне, как решить эту проблему.Ниже приведены коды, ребята .. 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);
}
?>

Ответы [ 3 ]

0 голосов
/ 10 июня 2018

Просто измените свой 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();
            }
        });
    });
});

Каждый раз, когда вы нажимаете кнопку отправки, открываете Chromedevtool> network> XHR и посмотрим, что получится.

0 голосов
/ 10 июня 2018

Во-первых, я не уверен, нужно ли использовать одинарные кавычки в столбце базы данных, а только в значениях, которые должны быть получены: это то, что я имею в виду

UPDATE salary SET salary_id ='$salary' 

Во-вторых, я включен, если isset должен получить формуотправить кнопку название

0 голосов
/ 10 июня 2018

Попробуйте это

$("#form6").submit(function() {
    $.post("modify_func.php", $("#form6").serialize());
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...