php delete multiple rows part 2

      Comments Off on php delete multiple rows part 2

Go back to php delete multiple rows part 1

If you are working with core php programming then you must require to deal with multiple rows at once. For example you can change status of multiple row at once. you want to delete multiple rows at once and so on. Here is the complete code to perform task on multiple rows with complete coding.


File: index2.php


// PHP Delete multiple rows using checkboxes, PHP and MySQL
// from :

//Connection to mysql

//fetch checkbox array of selected students id
$delete_checkbox_array = $_POST['students'];

//process one by one student and delete from student table of mydb database (mysql)
foreach ($delete_checkbox_array as $one_by_one_sid) 
	$query="delete from student where sid=$one_by_one_sid";
	$result= mysqli_query($con, $query) or die("Error");

//Check Record is deleted or not and revert back with message
if (mysqli_affected_rows($con) > 0) 
	$_SESSION["msg"]="Student(s) Deleted";
	header('Location: index.php');
	$_SESSION["msg"]="Error.. Please try again";
	header('Location: index.php');

Output 1

php delete multiple rows

Output 2

php delete multiple rows

Download Complete Code with SQL