weixin_33743661 2018-02-18 12:39 采纳率: 0%
浏览 20

删除按钮不起作用

TIA.I have two buttons one is Next(#next) which post the id(PRIMARY/AI) one at a time from database in a commentbox (already working). and the Processed(#processed) which or must delete the row (the id shown in commentbox)from the database every time it clicks. I have the code : and really sorry if its not good, I'm using Ajax too:

PS: the codes is compilation of many tutorials PS: the processed button (delete) is the only problem here

This the JS:

<script>
    //jQuery code here!
    $(document).ready(function() {
        var commentCount = 0;
        $("#next").click(function() {
        commentCount += 1;
            $("#comments").load("load-comments.php", {
                commentNewCount: commentCount
            });
               $("#processed").removeAttr('disabled');
               $(this).attr('disabled', 'disabled');
        });
        $("#processed").click(function() {
            var element = $("#comments");
            var commentNewCount = element.attr("commentCount");
            var info = 'commentCount=' +commentNewCount;
            // alert(info);
            if(confirm("Are you sure you want to delete this row?")){
                  $.ajax({
                      url: 'deleteuser.php',
                      type: 'post',
                      data: info, 
                      success: function(){
                      }
                  });

                  $("#comments").parent().parent().fadeOut(500, function(){
                  $("#comments").remove();
                  });

            }
            return false;
               });
         $("#next").removeAttr('disabled');
         $(this).attr('disabled', 'disabled');
        });
</script>

phpcode in Next button:

 <?php
    include 'dbh.php';

    $commentNewCount = $_POST['commentNewCount'];
    $sql = "SELECT * FROM comments LIMIT 1 OFFSET $commentNewCount";
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            echo $row['id'];

        }
    } else {
        echo "There are no queue!";
    }

?>

phpcode in Processed button:

    <?php
include 'dbh.php';

$userid =$_POST['id'];

$delete = mysqli_query($con, "DELETE FROM comments WHERE id=$commentNewCount");
if(!$delete){
echo "The queue Are already Delete" ;
}else{
echo "Success";
}
?>
  • 写回答

1条回答 默认 最新

  • 7*4 2018-02-18 13:01
    关注

    In the frontend, you're using

    var info = 'commentCount=' +commentNewCount;
    

    while in PHP code you're not getting it, you should use

    $commentNewCount =$_POST['commentCount'];
    

    in the PHP deletion code, there is no 'id' POST value

    also, pay attention to variable names, it's not clear if you're deleting a comment or a user

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错