Delete multiple records using checkbox in php

Create deletemultiple.php file.

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
<script language="javascript">
function validate()
var chks = document.getElementsByName('checkbox[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
if (chks[i].checked)
hasChecked = true;
if (hasChecked == false)
alert("Please select at least one.");
return false;
return true;
<table width="600" border="0" cellspacing="1" cellpadding="0">
<td><form name="form1" method="post" action="" onSubmit="return validate();">
<table width="500" border="0" cellpadding="3" cellspacing="1" bgcolor="#ddd">
<td colspan="4"><strong>Delete Multiple Records using Checkbox in PHP</strong> </td>
<td style=" width:10%"><strong>Id</strong></td>
<td style=" width:30%"><strong>Name</strong></td>
<td style=" width:20%"><strong>Class</strong></td>
<td style=" width:40%"><strong>Email</strong></td>



<td><input name="checkbox[]" type="checkbox" id="checkbox[]" 
value="<?php echo $rows['id']; ?>"></td>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['class']; ?></td>
<td><?php echo $rows['email']; ?></td>


<td><input name="delete" type="submit" id="delete" value="Delete"></td>


// Check if delete button active, start this
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
// if successful redirect to delete_multiple.php
echo "<meta http-equiv=\"refresh\" content=\"0;URL=deletemultiple.php\">";

Vineet Kumar Saini








When you click on delete button without select any checkbox then can’t delete i.e.

Vineet Kumar Saini









Now you can select any check box then click on delete button then

Vineet Kumar Saini






Delete multiple records using checkbox in php

Categories: Joomla, PHP & Joomla | Tags: , , , , , , | 19 Comments

Post navigation

19 thoughts on “Delete multiple records using checkbox in php

  1. keerthana

    this article is really amazing and its working also thanks for your sharing

  2. keerthana

    i have a doubt on this line.what is the use of form the delete button knows the help

    thanks in advance

  3. Hi sir,

    This code is really amazing and its working.
    thank you for sharing…………

    Sanajy Shelar

  4. thank you so much sir,

  5. Jatin nagendra


  6. shingala sohil


  7. gaurav

    bro i want insert update delete sorting paggination on one page with single n multyple

  8. thanks dude.. i’ve been looking for simple and working codes. and u help me with thid.not just it understandable.. it also WORKING!!

  9. Rohit Gour

    thanks for this code

  10. samuel

    worked perfectly

  11. Monika

    thanks a ton…

  12. deepmala

    Thanks really nice artical

  13. noel

    Excellent code….neat and good

  14. rajesh patidar maheshwar



  16. Thanks a ton. It’s really helpful. Good work there.!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: