First we create a new data display page view.php:
Copy the Code code as follows:
$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 "
"; echo "
Department Name |
Employee Name |
PC Name |
"; while ($row = Mysql_fetch_object ($rs)) echo "
Id ' >del |
$row->depart |
$row->ename |
"; echo "
";
?>
Unlike the General Data display page, this time there is a "Del" connection before each record, and by clicking del we can delete the corresponding data record in MySQL. The meaning of the red part of the program is: When you click del, the ID number of the corresponding record is passed to dodel.php.
Next look at dodel.php:
Copy the Code code as follows:
$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 "Delete succeeded!";
Mysql_close ($link);
?>
This page is the key to this topic, it receives the ID number from view.php, and it is used to delete the record of the SQL statement, so as to achieve the purpose of deleting the record.
Let's take a look at the SQL statements for MySQL data removal:
Delete from table name WHERE Condition = value
The value here is received by $del_id=$_get["id"], passed to the SQL statement, and finally executed by mysql_query to execute the SQL statement.
OK, can you confirm that the data in MySQL has been deleted correctly? If you have any questions, you can just leave a message to ask ~
Author: Sunec
Original download: Cenus Blog
The above describes the make me cry makes me smile the MySQL Delete record operation code with PHP, including content made me cry makes me smile, I hope to be interested in PHP tutorial friends helpful.