首页 > 代码库 > checkbox 删除

checkbox 删除

先创建del.php文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>删除</title>
</head>

<body>
<form action="sc.php" method=post>
<table border=1 width=60% align=center>
<caption></caption>
<th>选项</th><th>学号</th><th>姓名< /th><th>性别</th><th>电话</th>
<?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;
?>
<tr>
<td> <input type="checkbox" name="de[]" value="http://www.mamicode.com/<?php echo $id?>"/></td><td><?php echo $id?></td><td><?php echo $name?></td><td><?php echo $sex?></td><td><?php echo $phone?></td>
</tr>
<?php
}
mysql_close();
?>
</table>
<center><input type="submit" value="http://www.mamicode.com/删除"></center>
</form>

</body>
</html>

 

在创建sc.php


<?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 删除