PHP implements the MySQL update record code. First, sort out the operation logic: list all data and select the data records to be modified to enter the editable state. Submit the modification results and complete the modification. first, list the data views in the database. first, sort out the operation ideas:
List all data
Select the data record to be modified to enter the editable state.
Submit modification results to complete modification
First, list the Data view. php in the database, and add a modify character before each record, so that you can select the record you want to modify.
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 name |
Employee Name |
PC name |
";While ($ row = mysql_fetch_row ($ rs) echo"
Modify |
$ Row [1] |
$ Row [2] |
$ Row [3] |
$ Row [4] |
$ Row [5] |
$ Row [6] |
$ Row [7] |
$ Row [8] |
$ Row [9] |
$ Row [10] |
$ Row [11] |
$ Row [12] |
$ Row [13] |
";Echo"
";
?>
After you click modify, the editable status of the corresponding record is modify_do.php:
The code is as follows:
$ Link = mysql_connect ("localhost", "root", "administrator password ");
If (! $ Link) {die ("error ");}
Echo "mysql connection successful ";
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 result displayed ");}
?>
Finally, process the submitted data modify_finish.php:
The code is as follows:
$ Link = mysql_connect ("localhost", "root", "administrator password ");
If (! $ Link) {die ("error ");}
Echo "mysql connection successful ";
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 the data and add the last update time
Echo "modified successfully! ";
Mysql_close ($ link); // Close the dataset
?>
By Sunec
Original load: Cenus Blog
Copyright. The author and original source and this statement must be indicated in the form of links during reprinting.
Select the data records to be modified to edit all the data. Submit the modification result and complete the modification. first, list the data view in the database ....