How to delete data in batches in php
How to implement batch deletion of data in php
First, submit the ID of the data to be deleted on the front end to the backend php in the form of an array; Then use "$_GET" in php to get the data ID to be deleted, and finally connect to the MySQL database to delete the data one by one or use "IN" to delete it all at once.
Sample code
HTML:
<form id="form2" name="form2" method="post" action="del_product.php"> <label> <input type="checkbox" name="id[]" value="1" style="background:none; border:none;" /> 1 </label> <label> <input type="checkbox" name="id[]" value="2" style="background:none; border:none;" /> 2 </label> <label> <input type="checkbox" name="id[]" value="3" style="background:none; border:none;" /> 3 </label> <label> <input type="checkbox" name="id[]" value="4" style="background:none; border:none;" /> 4 </label> <label> <input type="checkbox" name="id[]" value="5" style="background:none; border:none;" /> 5 </label> <div style="padding-left:20px;"> <input type="button" value="全选" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onClick="selectBox('all')"/> <input type="button" value="反选" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onClick="selectBox('reverse')"/> <input type="submit" name="btnSave" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" value="删除"/> </div> </form>
PHP:
if($_POST['btnSave']){ if(empty($_POST['id'])){ echo"<script>alert('必须选择一个产品,才可以删除!');history.back(-1);</script>"; exit; } else { /*如果要获取全部数值则使用下面代码*/ $id= implode(",",$_POST['id']); $str="DELETE FROM `product` where id in ($id)"; mysql_query($str); echo "<script>alert('删除成功!');window.location.href='product_list.php';</script>"; } }
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of How to delete data in batches in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
