Delete multiple records using checkbox in php

Delete multiple records using checkbox in php

Create deletemultiple.php file.

<?php
$host="localhost";
$username="root";
$password="";
$db_name="test";
$tbl_name="student";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>

function validate()
{
var chks = document.getElementsByName('checkbox[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select at least one.");
return false;
}
return true;
}





















<?php
while($rows=mysql_fetch_array($result)){
?>









<?php
}
?>





<?php

// Check if delete button active, start this
if(isset($_POST['delete'])){
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id=$_POST['checkbox'][$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result)
{
echo "";
}
}
mysql_close();
?>
 Delete Multiple Records using Checkbox in PHP
IdNameClassEmail
<input name="checkbox[]" type="checkbox" id="checkbox[]"
value="">


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
About these ads

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

w

Connecting to %s