Home >Backend Development >PHP Tutorial >How to do batch deletion in PHP? _PHP Tutorial
How to do batch deletion in PHP? Please code
I am working on a project recently, but batch deletion has never been able to achieve the effect. I’ve posted the code below. Can you guys help me find out where the problem lies? Thank you very much!
//1. Batch deletion
if($_POST["chk"]){
$sid = implode(",", $_POST["chk"]);
$query = mysql_query("delete from news where news_id in (".$sid.")");
if($query){
echo "";
}
else {
echo "";
}
}
No matter how you delete it this way, it won’t work. Sometimes you can delete it by clicking Cancel. I don’t know why. Please ask an expert to answer it.
------Solution--------------------
Let’s echo the sql statement to see what is executed. If it doesn’t work, I’m thinking of other solutions
------Solution--------------------
This problem is easy to solve. Just print $_POST["chk"] and print the SQL statement and the problem will be solved
------Solution--------------------
It is recommended that you post your complete code
------Solution--------------------
echo "";
Your checkbox does not give a value.
------Solution--------------------
Click Cancel to delete because this sentence should be written like this:
There is also the del() function:
if(num==0){
alert("Please select!");
return false;
}