此问题已在此处有答案:
How can I bind an array of strings with a mysqli prepared statement?(7个回答)
How to include a PHP variable inside a MySQL statement(5个答案)
16小时前关闭
我在删除多条记录时遇到MySQL数据库中主键属性的数据类型问题。我试图删除数据库表中的多条记录,其主键属性具有“varchar”数据类型。我没有得到任何错误,但记录不删除。
然后我用“autoincrement”将主键属性的数据类型更改为“int”,并尝试使用相同的代码,然后它可以正常工作。却不知道为什么有人能看出是什么导致了这种奇怪的行为吗?我希望删除多个主键属性的数据类型为“varchar”的记录。”
tblmproduct表:
| 姓名|类型|
| --------------|--------------|
| Product_code(Primary)|中文(简体)|
| 批号|中文(简体)|
| 产品名称|中文(简体)|
| 生产日期|日期|
| EXP_date|日期|
| 供应商_id|整数(10)|
联系我们
<span class="custom-checkbox">
<input type="checkbox" class="product_checkbox" data-product-id="<?php echo $row["Product_code"]; ?>">
<label for="checkbox2"></label>
</span>
脚本:
$(document).on("click", "#delete_multiple", function () {
var product = [];
$(".product_checkbox:checked").each(function () {
product.push($(this).data("product-id"));
});
if (product.length <= 0) {
alert("Please select records.");
} else {
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this Record !",
icon: "warning",
buttons: true,
dangerMode: true,
}).then((willDelete) => {
if (willDelete) {
var selected_values = product.join(",");
$.ajax({
type: "POST",
url: "save-mproduct.php",
cache: false,
data: {
type: 4,
id: selected_values,
},
success: function (response) {
var ids = response.split(",");
for (var i = 0; i < ids.length; i++) {
location.reload();
$("#" + ids[i]).remove();
}
},
});
swal("Record Deleted successfully !", {
icon: "success",
});
} else {
swal("Your imaginary file is safe!");
}
});
}
});
save-mproduct.php:
if(count($_POST)>0){
if($_POST['type']==4){
$id=$_POST['id'];
$sql = "DELETE FROM tblmproduct WHERE Product_code IN ($id)";
if (mysqli_query($con, $sql)) {
echo $id;
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}
mysqli_close($con);
}
}
2条答案
按热度按时间brccelvz1#
试试这个
vlf7wbxs2#
试试这个:
这一定能成功!