Home > Backend Development > PHP Tutorial > checkbox deletion, checkbox_PHP tutorial

checkbox deletion, checkbox_PHP tutorial

WBOY
Release: 2016-07-13 10:15:48
Original
1010 people have browsed it

checkbox 删除,checkbox

先创建del.php文件:





删除






$link=mysql_connect("localhost","root","123456");
mysql_select_db("logisticsdb0123");
mysql_query("set names utf8");
$exec="select * from logistics_accident";
$result=mysql_query($exec);
while($rs=mysql_fetch_object($result))
{
$id=$rs->ID;
$name=$rs->Name;
$sex=$rs->PlaceAddress;
$phone=$rs->Remark;
?>



}
mysql_close();
?>
选项学号姓名< /th>性别电话





 

在创建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');

checkbox 多选删除

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?

CHECKBOX checkbox to delete multiple records

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)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/902435.htmlTechArticlecheckbox Delete, checkbox First create the del.php file: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xm...
Related labels:
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