Student Information Table
Options"/>
Student Information Table
Options">

Home  >  Article  >  Backend Development  >  checkbox php How to delete multiple records at one time using checkbox

checkbox php How to delete multiple records at one time using checkbox

WBOY
WBOYOriginal
2016-07-29 08:42:001040browse

A simple example
There is a student information database and multiple records need to be deleted at one time
Create a file named del.php
The code is as follows:

Copy the codeThe code is as follows:






$link= mysql_connect("localhost","root","");
mysql_select_db("zs");
$exec="select * from student";
$result=mysql_query($exec);
while($rs=mysql_fetch_object ($result))
{
$id=$rs->sID;
$name=$rs->sName;
$sex=$rs->sSex;
$ph
?>
< tr>


}
mysql_close();
?>
Student Information Table
Options Student IDName< /th>GenderPhone number >< ?php echo $phone?>




This file is mainly used to display the data in the database and display it.
Create another file named sc.php with the following code:

Copy the code The code is as follows:


$link=mysql_connect("localhost","root","" );
mysql_select_db("zs");
$id=$_POST['de'];
foreach($id as $ide){
$exec="delete from student where sID=$ide";
$result =mysql_query($exec);
if((mysql_affected_rows()==0) or (mysql_affected_rows==-1))
{
 echo "No record found, or error while deleting";
exit;
}
else{
 echo "Student information has been deleted";
  }
  }
  mysql_close();
?>


Use foreach to delete the records respectively.

The above introduces the checkbox php method of using checkbox to delete multiple records at one time, including the checkbox content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn