Home >Backend Development >PHP Tutorial >checkbox deletion, checkbox_PHP tutorial
先创建del.php文件:
在创建sc.php
$link=mysql_connect("localhost","root","123456");
mysql_select_db("logisticsdb0123");
$id=$_POST['de'];
foreach($id as $ide){
$exec="delete from logistics_accident where ID='$ide'";
echo $exec;
$result=mysql_query($exec);
echo $result;
if((mysql_affected_rows()==0) or (mysql_affected_rows==-1))
{
echo "没有找到记录,或者删除时出错";
exit;
}
else{
echo "信息已经删除";
}
}
mysql_close();
?>
数据库数据:
-- phpMyAdmin SQL Dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2014 年 10 月 29 日 08:50
-- 服务器版本: 5.0.51
-- PHP 版本: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- 数据库: `logisticsdb0123`
--
CREATE DATABASE `logisticsdb0123` DEFAULT CHARACTER SET gb2312 COLLATE gb2312_chinese_ci;
USE `logisticsdb0123`;
-- --------------------------------------------------------
--
-- 表的结构 `logistics_accident`
--
CREATE TABLE `logistics_accident` (
`ID` varchar(5) NOT NULL,
`Name` varchar(50) NOT NULL,
`PlaceTime` date NOT NULL,
`Time` date NOT NULL,
`PlaceAddress` varchar(50) NOT NULL,
`Remark` varchar(100) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;
--
-- 导出表中的数据 `logistics_accident`
--
INSERT INTO `logistics_accident` (`ID`, `Name`, `PlaceTime`, `Time`, `PlaceAddress`, `Remark`) VALUES
('A001', '123132', '2014-09-17', '2014-09-05', '1313', '0123');
This is a very common code and very simple. In your case, you can use a hidden input. When you click the delete button, you can detect which record checkboxes are selected and put the IDs of these records into In that hidden input. Then submit. You can also have a checkbox and a hidden input. When a checkbox is selected, the corresponding hidden input is set to the ID of the record. If canceled, it will be left empty. These hidden inputs use the same name.
For example, rs is the returned record set:
do until rs.eof
'Write checkbox
response.write ""
'Write hidden
response.write ""
……'Other processing Code
rs.movenext
loop
To process the submitted code, just detect request.form("todel") or request.querystring("todel") or request("todel") . The record will not be deleted after obtaining the ID number, so that should be impossible, right?
How to use asp to select multiple check boxes and delete multiple records at one time?
Method 1
For Each items in Request.Form("Checkbox")
sql=""
conn.execute(sql)
next
Method 2
is to use split(str,",") to separate the deletions one by one, the code is as follows
needdelete =request("checkbox")
array =split(needdelete,",")
for i=0 to ubound(array)
conn.execute(sql)
next
Method 3
is to use sql, delete from tablename where id in("&request("checkbox")&")
conn.execute(sql)