php delete multiple rows

      Comments Off on php delete multiple rows

php delete multiple rows

php Deleting multiple rows

PHP delete multiple rows is commonly required in all PHP admin sides. Here are complete tutorials on how you can fetch all records from the database and display with checkbox and operations like delete all or selected records. One more functionality I have added is select all check box at once by clicking on the checkbox at top of the records.

PHP is world’s most popular languages and used by almost more than 50% of websites. Here is the PHP tutorial on the selection of multiple rows using check box which is must for every operation.

Did you know, You can upload file using php.

File: index.php

<?php
session_start();

//=========================================================
// PHP Deleting multiple rows using checkboxes, PHP and MySQL
// from : http://adarshspatel.in
//==========================================================

//Connection to mysql
$con=mysqli_connect(“localhost”,”root”,””,”mydb”);

//Fetch Student Records
$query=”select * from student”;
$result= mysqli_query($con, $query) or die(“Error…”);

//Count total number of rows available
$count = mysqli_affected_rows($con);

?>

<html>
<head>
<title>    Deleting multiple rows using checkboxes, PHP and MySQL    </title>

<script language=”JavaScript”>

//function to check or unchecked all checkbox on single click
function CheckUnCheckAll(source)
{
checkboxes = document.getElementsByName(‘students[]’);
for(var i=0, n=checkboxes.length;i<n;i++)
{
checkboxes[i].checked = source.checked;
}
}
</script>

</head>
<body>
<h2>php Delete multiple rows using checkboxes, PHP and MySQL</h2>
<h2>JavaScript & PHP checkbox select all </h2>

<form method=”post” action=”index2.php”>

<table border=”1″>
<tr>
<td> <input name=”selectall” type=”checkbox” onClick=”CheckUnCheckAll(this)” />  </td>
<td>sid</td>
<td>sname</td>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><input id=”students[]” name=”students[]” type=”checkbox”  id=”checkbox[]” value=”<?php echo $row[‘sid’]; ?>”></td>
<td> <?php echo $row[‘sid’]; ?> </td>
<td> <?php echo $row[‘sname’]; ?> </td>
</tr>

<?php
}
?>

</table>
<br><br>
<input name=”delete” type=”submit”   id=”delete” value=”Delete StudentsFiles”>
</form>

<?php
if(isset($_SESSION[‘msg’]))
{
//echo “”$_SESSION[‘msg’];
echo “<script language=\”JavaScript\”>alert(\””.$_SESSION[“msg”].”\”);</script>”;
unset($_SESSION[‘msg’]);
}
?>

Continue Reading…