Checkbox deletion, checkbox

Source: Internet
Author: User

Checkbox deletion, checkbox

Create the del. php file first:

<! 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> Delete </title>
</Head>

<Body>
<Form action = "SC. php" method = post>
<Table border = 1 width = 60% align = center>
<Caption> </caption>
<Th> Option </th> <th> Student ID </th> <th> name </th> <th> gender </th> <th> phone number </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 = "<? Php echo $ id?> "/> </Td> <? Php echo $ id?> </Td> <? Php echo $ name?> </Td> <? Php echo $ sex?> </Td> <? Php echo $ phone?> </Td>
</Tr>
<? Php
}
Mysql_close ();
?>
</Table>
<Center> <input type = "submit" value = "delete"> </center>
</Form>

</Body>
</Html>

 

Create 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 "no record found or an error occurred while deleting ";
Exit;
}
Else {
Echo "information deleted ";
}
}
Mysql_close ();
?>

Database Data:

-- PhpMyAdmin SQL Dump
-- Version 2.11.6
Http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Date: October 29, 2014
-- Server version: 5.0.51
-- PHP version: 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 */;

--
-- Database: 'logisticsdb0123'
--
Create database 'logisticsdb0123 'default character set gb2312 COLLATE gb2312_chinese_ci;
USE 'logisticsdb0123 ';

----------------------------------------------------------

--
-- Table structure '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;

--
-- Export the data 'logistics _ accident' In the table'
--

Insert into 'logistics _ accident '('id', 'name', 'placetime', 'time', 'placeaddress', 'remark') VALUES
('A001', '000000', '2017-09-17 ', '2017-09-05', '20170901', '20170901 ');


Checkbox multiple-choice Deletion

This is a very common code, and it is very simple. In this case, you can use a hidden input to check which records are selected when you click the delete button, put the IDs of these records in the hidden input. Then submit. You can also set a checkbox and a hidden input. When you select a checkbox, the corresponding hidden input value is set to the record ID. If you cancel the operation, it is set to null. The several den inputs use the same name.

For example, rs is the returned record set:
Do until rs. eof
'Write checkbox
Response. write "<input type = checkbox onclick =" "if (this. checked) document. all. todel _ "& rs (" id ")&". value = '"& rs (" id ") &"'; else document. all. todel _ "& rs (" id ")&". value = ''" ">"
'Write den
Response. write "<input type = hidden name = todel id = todel _" & rs ("id") & ">"
...... 'Additional processing code
Rs. movenext
Loop

To process the submitted code, you only need to check the request. form ("todel"), request. querystring ("todel"), or request ("todel. The records won't be deleted after the ID number is obtained. Isn't it possible?

CHECKBOX check box Delete multiple records

How does asp select multiple check boxes and delete multiple records at a time?

Method 1

For Each items in Request. Form ("Checkbox ")
SQL = ""
Conn.exe cute (SQL)
Next

Method 2

It is to use split (str, ",") to separate individual deletions, the Code is as follows:

Needdelete = request ("checkbox ")

Array = split (needdelete ,",")

For I = 0 to ubound (array)

Conn.exe cute (SQL)

Next

Method 3

The SQL statement is used. delete from tablename where id in ("& request (" checkbox ")&")

Conn.exe cute (SQL)
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.