PHP implements the MySQL update record Code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags mysql update
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" ";While ($ row = mysql_fetch_row ($ rs) echo" ";Echo"
Department name Employee Name PC name
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]
";
?>



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 ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.