Today we will show you how to modify data records in MySQL through PHP. The update statement is used to sort out the operation logic first:
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: http://www.cenusblog.com "target = _ blank> Cenus Blog
Copyright. The author and original source and this statement must be indicated in the form of links during reprinting.