You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP+JQuery/Ajax+Mysql环境下DELETE删除后表中数据行仍存在问题

MySQL删除操作返回成功但记录未消失问题排查

使用技术栈为 php + jquery/ajax + mysql,插入记录功能正常。

问题复现步骤

  • 通过ajax向空Mysql表插入一行数据,操作成功,确认表中存在该条唯一记录
  • 通过ajax请求删除该条唯一记录,控制台返回mysqli_affected_rows为1,提示删除成功无报错无警告
  • 查看数据库表发现该条记录仍然存在,仅当再新增一条记录后,可删除旧的非最后一行记录,新的最后一行仍存在相同问题

相关代码

后端删除逻辑代码

$sql=mysqli_query($connmysql,"DELETE from locations where iddata='97' and location='01-N-D-34' and  items='48'")or die(mysqli_error($connmysql)); 

echo mysqli_affected_rows($connmysql);
$connmysql->close();

前端删除请求代码

$.ajax({
    type: "POST",
    url: "delete.php",                             
    dataType: "text",       
    success: function(response) {
        console.log(response);                              
    },
    error: function(xhr,textStatus,err) {
        console.log("readyState: " + xhr.readyState);
        console.log("responseText: "+ xhr.responseText);
        console.log("status: " + xhr.status);
        console.log("text status: " + textStatus);
        console.log("error: " + err);
    }
}); 

根因结论

jQuery类名绑定位置错误,点击删除按钮时同时触发了插入和删除事件,删除记录后又重新插入了内容完全相同的记录,因此从表象上看记录没有被成功删除。


内容的提问来源于stack exchange,提问作者Alex Coloma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 04:57:04