Home >Backend Development >PHP Tutorial >make me cry make me smile MySQL record deletion operation code using PHP

make me cry make me smile MySQL record deletion operation code using PHP

WBOY
WBOYOriginal
2016-07-29 08:38:051093browse

First, we create a new data display page view.php:

Copy the code The code is 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 nameEmployee namePC name";
while($row = mysql_fetch_object($rs)) echo "del< /td>$row->depart$row->ename";
echo "";
? >


Different from the general data display page, this time, there is a link with the word "del" before each record. By clicking del, we can delete the corresponding data record in MySQL. The meaning of the red part in the above program is: when del is clicked, the ID number of the corresponding record is passed to dodel.php.
Next go to dodel.php:

Copy the code The code is 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 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, thus To achieve the purpose of deleting the record.
Let’s take a closer look. The SQL statement used to delete MySQL data is:
delete from table name where condition = value
We receive the value here through $del_id=$_GET["id"] and pass it to the SQL statement , and finally execute this SQL statement through mysql_query.
Okay, can you confirm whether the data in MySQL has been deleted correctly? If you have any questions, you can leave a message directly~
Author: Sunec
Original: Cenus Blog

The above introduces the make me cry make me smile MySQL record deletion operation code using PHP, including the content of make me cry make me smile. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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