数据库行未删除,AJAX,PHP错误 [英] Database row is not deleting, AJAX, PHP error

查看:95
本文介绍了数据库行未删除,AJAX,PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从HTML表中删除数据库行数据.我有一个HTML表,其中已调用所有数据库表值.我想给用户一个删除顺序选项.我为此使用了删除按钮.为此,我正在尝试将ajax和jquery与php delete查询一起使用.但是问题是当我单击删除时,它只是删除HTML行数据.它也应该从数据库中删除该特定的id行.我需要你的帮助.请让我知道我做错了什么?我对ajax和jquery非常陌生.

I want to remove DB row data from HTML table. I have an HTML table where I have called all the database table values. I want to give a delete order option to the user. I have used a delete button for that. To do this, I am trying to use ajax and jquery with php delete query. But the issue is When I click on delete it just deletes the HTML row data. It should delete that particular id row from DB as well. I need your help. Please let me know what I have done wrong? I am very much new to ajax and jquery.

remove.php

remove.php

<?php 
include "config.php";

$id = $_REQUEST['id'];

// Delete record
$query = "DELETE FROM mi_home_tv WHERE id='$id'";
mysqli_query($link,$query);

echo 1;

jquery+ajax code
<script src='jquery-3.0.0.js' type='text/javascript'></script>
<script type="text/javascript">
    $(document).ready(function(){

    // Delete 
    $('.delete').click(function(){
        var el = this;
        var id = this.id;
        var splitid = id.split("_");

        // Delete id
        var deleteid = splitid[1];

        // AJAX Request
        $.ajax({
            url: 'remove.php',
            type: 'POST',
            data: { id:deleteid },
            success: function(response){

                // Removing row from HTML Table
                $(el).closest('tr').css('background','tomato');
                $(el).closest('tr').fadeOut(800, function(){      
                    $(this).remove();
                });
            }
        });
    });
});
</script>

按钮代码:

echo "<td> <span  id='del_<?php echo $id; ?>'  type='submit' class=' delete btn c-theme-btn c-btn-uppercase btn-xs  c-btn-square c-font-sm'>Delete</span> </td>";

php代码:

 <form method="post" action="remove.php">
                                        <?php
                                       echo " <thead>
                                            <tr>

                                                <th>Order ID</th>
                                                <th>Date</th>
                                                <th>Name</th>
                                                 <th>Store Name</th>
                                                <th>Zip</th>
                                                <th>City</th>
                                                <th>Address</th>
                                                 <th>Contact</th>
                                                  <th>Tv Varient</th>
                                                  <th>Total</th>
                                                   <th>Delivery</th>
                                                  <th>Action</th>
                                            </tr>
                                        </thead>

                                              <tbody>";
                                               while($row = mysqli_fetch_array($result))
                                          {
                                             $id = $row['id'];

                                           echo"<tr>";
                                                echo "<td>" . $row['id'] . "</td>";
                                                echo "<td>" . $row['rdate'] . "</td>";
                                                echo "<td>" . $row['rname'] . "</td>";
                                                echo "<td>" . $row['rstore'] . "</td>";
                                                echo " <td>" . $row['rzip'] . "</td>";
                                                echo "<td>" . $row['rcity'] . "</td>";
                                                echo "<td>" . $row['raddress'] . "</td>";
                                                echo "<td>" . $row['rphone'] . "</td>";
                                                echo "<td>" . $row['rtv_varient'] . "</td>";
                                                echo"<td>" . $row['ramount'] . "</td>";
                                                echo"<td>" . $row['rdelivery'] . "</td>";

                                                echo "<td> <input type='submit' value='delete'  id='del_<?php echo $id; ?>' type='submit' class=' delete btn c-theme-btn c-btn-uppercase btn-xs  c-btn-square c-font-sm'>Delete</button> </td>";

                                                  echo"</tr>";


                                                 }
                                                 ?>
                                             </form>

推荐答案

您应该具有一个表单,该表单的输入如下:

You should have a form which will have an input as follows:

<form method="post" action="remove.php">
<input type="submit" value="Delete" name="id" />
</form>

这篇关于数据库行未删除,AJAX,PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆