First, create the data display page view. php:
Copy codeThe Code is as follows:
<? Php
$ Link = mysql_connect ("localhost", "root", "administrator password ");
Mysql_select_db ("infosystem", $ link );
$ Q = "SELECT * FROM info ";
Mysql_query ("set names GB2312 ");
$ Rs = mysql_query ($ q, $ link );
Echo "<table> ";
Echo "<tr> <td> Department name </td> <td> employee name </td> <td> PC name </td> </tr> ";
While ($ row = mysql_fetch_object ($ rs) echo "<tr> <td> <a href = 'dodel. php? Id = $ row-> id'> del </a> </td> <td> $ row-> depart </td> <td> $ row-> ename </ td> </tr> ";
Echo "</table> ";
?>
Unlike the general data display page, this time, there is a connection with "del" before each record. By clicking del, we can delete the corresponding data records in MySQL. The red part of the above program indicates that when del is clicked, the ID number of the corresponding record is passed to dodel. php.
Next let's see dodel. php:
Copy codeThe Code is as follows:
<? Php
$ Link = mysql_connect ("localhost", "root", "administrator password ");
Mysql_select_db ("infosystem", $ link );
$ Del_id = $ _ GET ["id"];
$ Exec = "delete from info where id = $ del_id ";
Mysql_query ($ exec, $ link );
Echo "deleted successfully! ";
Mysql_close ($ link );
?>
This page is the key to this topic. It receives the ID number from view. php and substitutes it into the SQL statement used to delete the record, so as to delete the record.
Let's take a closer look. The SQL statement used to delete MySQL Data is:
Delete from table name where condition = Value
The value here is received through $ del_id = $ _ GET ["id"], passed to the SQL statement, and executed through mysql_query.
Okay. Can you check whether the data in MySQL has been deleted correctly? If you have any questions, please leave a message and ask questions ~
By Sunec
Original load: Cenus Blog