Home > Backend Development > PHP Tutorial > PHP code to implement MySQL update record_PHP tutorial

PHP code to implement MySQL update record_PHP tutorial

WBOY
Release: 2016-07-21 15:51:27
Original
865 people have browsed it


First, sort out the operation ideas:

List all data
Select the data record that needs to be modified and enter the editable state.
Submit the modification results to complete the modification
First list the data view.php in the database, and add the word "modify" before each record, so that users can select the records they want to modify for modification.

Copy 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 "";
while($row = mysql_fetch_row($rs)) echo "< ;td>$row[6]";
echo "
Department name Employee namePC name
< ;a href='modify_do.php?id=$row[0]'>modify$row[1]$row[ 2]$row[3]$row[4]$row[5]$row[7]$row[8]$row[9] $row[10]$row[11]$row[12]
";
?>



When the user clicks modify, enter the editable state of the corresponding record modify_do.php:

Copy code The code is as follows:


$link =mysql_connect("localhost","root","admin password");
if(!$link){die("error"); }
echo "Connect to mysql successfully";
mysql_select_db("infosystem", $link);
$del_id=$_GET["id"];
$q="select * from info where id=$del_id";

mysql_query("SET NAMES GB2312"); //Code conversion
$rs = mysql_query($q, $link);
if(!$rs){ die("No results displayed");}
?>








echo "";

while($row = mysql_fetch_object($rs)) echo "";

mysql_close($link); //Close the data set

?>






Finally, process the submission Data modify_finish.php:

Copy code The code is as follows:


$link =mysql_connect("localhost","root","administrator password");
if(!$link){die("error");}
echo "Connect to mysql successfully";
mysql_select_db("infosystem", $link);

mysql_query("SET NAMES GB2312");

$rs = mysql_query($q,$link);
$row = mysql_fetch_object($rs);
$exec="update info set ename='".$_POST['ename']."' where id=".$_POST['id'].""; //Modify Data and add the last update time

echo "Modification successful!" ;

mysql_close($link); //Close the data set

?>

Author: Sunec
Original Published by: Cenus Blog
All rights reserved. When reprinting, the author, original source and this statement must be indicated in the form of a link.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319134.htmlTechArticleFirst, sort out the operation ideas: List all data, select the data records that need to be modified, and enter the editable state. Submit the modification results to complete the modification. First list the data views in the database....
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