MySQL delete record operation code using PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:51:22
Original
836 people have browsed it

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 "";
while($row = mysql_fetch_object($rs)) echo "";
echo "
Department NameEmployee NamePC Name
del$row->depart< ;/td>$row->ename
";
?>

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

www.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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!