简体   繁体   English

删除按钮不起作用

[英]Delete Button didn't work

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). TIA.I 有两个按钮,一个是Next(#next) ,它从数据库中的commentbox一次一个地发布id(PRIMARY/AI) (已经在工作)。 and the Processed(#processed) which or must delete the row (the id shown in commentbox )from the database every time it clicks.Processed(#processed)每次点击时,它或必须从数据库中删除行( commentbox显示的 id)。 I have the code : and really sorry if its not good, I'm using Ajax too:我有代码:如果它不好,真的很抱歉,我也在使用 Ajax:

PS: the codes is compilation of many tutorials PS: the processed button (delete) is the only problem here PS:代码是很多教程的汇编 PS:处理的按钮(删除)是这里唯一的问题

This the JS:这是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:下一步按钮中的phpcode:

 <?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:已处理按钮中的 phpcode:

    <?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";
}
?>

In the frontend, you're using在前端,您正在使用

var info = 'commentCount=' +commentNewCount;

while in PHP code you're not getting it, you should use而在 PHP 代码中你没有得到它,你应该使用

$commentNewCount =$_POST['commentCount'];

in the PHP deletion code, there is no 'id' POST value在 PHP 删除代码中,没有 'id' POST 值

also, pay attention to variable names, it's not clear if you're deleting a comment or a user另外,请注意变量名称,不清楚您是删除评论还是用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM