Home > Backend Development > PHP Tutorial > Use checkbox to delete multiple records at once_PHP tutorial

Use checkbox to delete multiple records at once_PHP tutorial

WBOY
Release: 2016-07-21 14:55:09
Original
1058 people have browsed it

Answer a friend’s question: How to delete multiple records at once.
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 to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com]



< ;th>Options
$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;
$phone=$rs->sPhone;
?>

< td> >


}
mysql_close();
?>

This file is mainly used to display the data in the database and display it.

Create a file named sc.php with the following code:

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com]$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 an error occurred while deleting";
exit;
}
else{
echo "Student The information has been deleted";
}
}
mysql_close();
?>

Use foreach to delete the records respectively.

Source: http://www.cnblogs.com/walkbro/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364481.htmlTechArticleAnswer a friend’s question: How to delete multiple records at one time. 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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Student Information Table
Student IDName< /th>GenderPhone number