First, we create a new data display page view.php:
Copy the code The code is as follows:
$ link=mysql_connect("localhost","root","admin 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 "del | $row->depart< ;/td> | $row->ename |
";
echo "
";
?>
Different from the general data display page, this time, there is a connection 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 look at dodel.php:
Copy the code The code is as follows:
$link =mysql_connect("localhost","root","admin 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, thereby achieving 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 pass the value here through $del_id=$_GET[ "id"] to receive and pass it to the SQL statement, and finally execute the 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
http://www.bkjia.com/PHPjc/319142.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319142.htmlTechArticleFirst we create a new data display page view.php: Copy the code as follows: ?php $link=mysql_connect("localhost ","root","Administrator password"); mysql_select_db("infosystem",$link); $q="S...