douqian1975 2017-11-09 20:59
浏览 30

JQuery删除了页面行,但Ajax没有删除db记录

I am trying to use jquery and ajax to remove the a row on the page and a record in the db but it's not working for me. The row on the page is removed successfully but the php file is not getting called. I just have an echo statement in the php to error check and that is not getting printed to the screen.

js file

function deleteLine(a,estimateNum,rowNum){
        var $rowcount = $("#desc_table tr").length;
        if($rowcount <= 2){
                alert("Cannot remove all the description lines.");
                return false;
        }
        else{
          if (confirm("Are you sure you want to delete?")) {
            $.ajax({
              type: "POST",
              url: "delete_desc_record.php",
               data: { estimate_num: estimateNum, row_num: rowNum },
              cache: false,
              success: function(){
                  a.closest('tr').remove();
                }
            });
          }
          else{
            return false;
          }
    }

delete_desc_record.php

<?php
include 'connect.php'; 
include 'set_variables.php';

$estimate_num = isset($_POST['estimate_num']) ? (int) $_post['estimate_num'] : 0;
$row_num = isset($_POST['row_num']) ? (int) $_post['row_num'] : 0;

echo 'in delete php file '. $estimate_num .' '. $row_num;

index.php

if(!empty($DESC)){
 foreach ($DESC as $i => $b) {
 ?>
 <tr>
 <td><input name="desc[]" type="text" value="<?php echo $DESC[$i]; ?>"></td> 
 <td> <input name="desc_hr[]" type="text" value="<?php echo $DESC_hr[$i]; ?>"</td>
 <td> <input name="desc_rt[]" type="text" value="<?php echo $DESC_rt[$i]; ?>" </td>
 <td><input name="desc_amt[]" type="text" value="<?php echo $DESC_amt[$i]; ?>"></td>
 <td><input type="button" value="X" name="delete" class="btnDelete" onclick="deleteLine(this,<?php echo $estimate_num .','. $i; ?>)"></td>
  </tr>
  <?php
  }
}
  • 写回答

2条回答 默认 最新

  • drmgg4411 2017-11-09 21:08
    关注

    Do you have any console errors in developer tools?

    So you should read up on prepared statements to prevent Sql injection and your DELETE statement is incorrect. Remove the asterisk.

    Update Just checking over your SQL query and cannot see where $cust_id is being set anywhere?

    Maybe check your include files, they may be breaking the entire script. If they seem to be fine then just write an echo statement at the top of your file, refresh the page, do you get anything printed on screen? If yes then move the echo line down and repeat the steps of refreshing the page until you no longer get the echoed text.

    If you have PHP errors on then you should see an error, make sure display_errors is set to 1 in your php.ini file.

    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线