PHP-无法使用复选框删除MySQL行(没有表单)

PHP-无法使用复选框删除MySQL行(没有表单),php,jquery,mysql,Php,Jquery,Mysql,首先,我想道歉,如果有任何重复的问题问 正如标题所说,我正试图删除用户在jQuery帮助下检查的多行。不幸的是,我未能完成这项任务 下面是我正在使用的代码:==> index.php-->以表格格式显示数据 <?php require_once '../../Classes/class.Validation.php'; $validate = new Validation('ecommerce'); $qu = "SELECT ProdCode, ProdName, ProdDescrip

首先,我想道歉,如果有任何重复的问题问

正如标题所说,我正试图删除用户在
jQuery
帮助下检查的多行。不幸的是,我未能完成这项任务

下面是我正在使用的代码:==>

index.php-->以表格格式显示数据

<?php
require_once '../../Classes/class.Validation.php';
$validate = new Validation('ecommerce');
$qu = "SELECT ProdCode, ProdName, ProdDescription, ProdRate, ProdTotalQuantity, ProdAvailability FROM products";
$validate->Query($qu);
if ($validate->NumRows()) {
?>
    <div class="container-fluid">
        <div class="table-responsive">
            <table border="1" class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th><input type="checkbox" id="all" name="deletePrd[]"></th>
                        <th>Prod-Image</th>
                        <th>Prod-Code</th>
                        <th>Prod-Name</th>
                        <th>Prod-Description</th>
                        <th>Prod-Rate</th>
                        <th>Prod-Quantity</th>
                        <th>Prod-Availability</th>
                        <th>Action</th>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                    <th>
                        <input class="filter" name="Pro-Code" placeholder="Prod-Code" data-col="Prod-Code">
                    </th>
                    <th>
                        <input class="filter" name="Prod-Name" placeholder="Prod-Name" data-col="Prod-Name">
                    </th>
                    <th>
                        <input class="filter" name="Prod-Description" placeholder="Prod-Description" data-col="Prod-Description">
                    </th>
                    <th>
                        <input class="filter" name="Prod-Rate" placeholder="Prod-Rate" data-col="Prod-Rate">
                    </th>
                    <th>
                        <input class="filter" name="Prod-Total-Quantity" placeholder="Prod-Quantity" data-col="Prod-Quantity">
                    </th>
                    <th>
                        <input class="filter" name="Prod-Availability" placeholder="Prod-Availability" data-col="Prod-Availability">
                    </th>
                        <th>&nbsp;</th>
                    </tr>
                    </thead>
                    <tbody>                 
                        <?php
                        while ( $row = $validate->FetchAllDatas() ) {
                            echo '<tr>
                            <td><input type="checkbox" id="'.$row["ProdCode"].'" name="deletePrd[]"></td>
                            <td>
                                <img src="http://www.example.com/ECommerce/Images/Products/'
                                .$row["ProdCode"].'.jpg" alt="'.$row["ProdName"].'"
                                width="75" height="50" />
                            </td>           
                            <td>' . $row["ProdCode"] . '</td>
                            <td>' . $row["ProdName"] . '</td>
                            <td>' . $row["ProdDescription"] . '</td>
                            <td>' . $row["ProdRate"] . '</td>
                            <td>' . $row["ProdTotalQuantity"] . '</td>
                            <td>' . $row["ProdAvailability"] . '</td>
                            <td>
                                <a href="http://www.example.com/ECommerce/Administrators/Products/UpdateProduct.php?prd='.$row["ProdCode"].'">UPDATE</a><br /><a href="http://www.example.com/ECommerce/ActionFiles/DeleteProduct.php?prd='.$row["ProdCode"].'">DELETE</a>
                            </td></tr>';
                        }
                        ?>                  
                    </tbody>
                </table>
            </div>
        </div>
        <?php
    } else {
        echo '<p class="lead">No Products. Start inserting by clicking <a href="http://www.example.com/ECommerce/Administrators/Products/AddProducts.php">here</a></p>';
    }
    ?>
替换

data: count_checked.serialize(),


在没有表单的情况下,要么使用ajax onClick发布数据,要么在URL上以逗号分隔作为查询参数传递多个选定ID,我该怎么做?问题是,我是这方面的初学者请注意:请注意:@GBD我在使用第二个链接中提供的答案时,将NULL作为输出。。现在检查更新的jQuery部件。。
$("a[id='del']").click(function() {
        var count_checked = $("[name='deletePrd[]']:checked").length;
        var checkedCode = $("[name='deletePrd[]']:checked").attr("id");
        if(count_checked == 0) {
            alert("Please select product(s) to delete.");
            return false;
        }
        if(count_checked == 1) {
            //return confirm("Are you sure you want to delete this product ?");
            if (confirm('Are you sure you want to delete this product ?')) {
                $("a[id='del']").attr("href", "http://www.example.com/ECommerce/ActionFiles/DeleteProduct.php?prdCode=" + checkedCode);
            }
        } else if(count_checked > 1) {
            if (confirm('Are you sure you want to delete the selected products ?')) {
                $("a[id='del']").attr("href", "http://www.example.com/ECommerce/ActionFiles/DeletedSelectedProducts.php");
                for (var i = 0; i < count_checked; i++) {
                    console.log(i);
                }
            }           
        }
    });
<?php
session_start();

require_once '../Classes/class.Validation.php';
$validate = new Validation('developi_ecommerce');

if (isset($_POST['DeleteLink']) && isset($_POST['deletePrd'])) {
    $delete = $_POST['deletePrd'];

    $res = "";

    foreach ($delete as $code) {
        $q = "DELETE FROM products WHERE ProdCode = '".$code."' ";
        $res = $validate->Query($q);
    }
    if (!$res) {
        echo '<br />Not Deleted';
    } else {
        echo '<br />Deleted';
    }
} else {
    echo 'Product Not Set';
}

if ($validate->IsConnected()) {
    $validate->DisConnect();
}
$("a[id='del']").click(function() {
        var count_checked = $("[name='deletePrd[]']:checked").length;
        var checkedCode = $("[name='deletePrd[]']:checked").attr("id");
        if(count_checked == 0) {
            alert("Please select product(s) to delete.");
            return false;
        }
        if(count_checked == 1) {
            //return confirm("Are you sure you want to delete this product ?");
            if (confirm('Are you sure you want to delete this product ?')) {
                $("a[id='del']").attr("href", "http://www.example.com/ECommerce/ActionFiles/DeleteProduct.php?prdCode=" + checkedCode);
            }
        } else if(count_checked > 1) {
            if (confirm('Are you sure you want to delete the selected products ?')) {
                /*$("a[id='del']").attr("href", "http://www.developigner.com/ECommerce/ActionFiles/DeletedSelectedProducts.php");
                for (var i = 0; i < count_checked; i++) {
                    console.log(i);
                }*/
                $("a[id='del']").
                attr("href", "http://www.developigner.com/ECommerce/ActionFiles/DeletedSelectedProducts.php").
                ajax({
                    type: "post",
                    data: count_checked.serialize(),
                    success: function() {
                        alert(count_checked);
                    }
                });
            }           
        }
    });
data: count_checked.serialize(),
data: $("[name='deletePrd[]']:checked").serialize(),