Use thinkPHP to update data: an example [original] and a thinkphp example _ PHP Tutorial

Source: Internet
Author: User
Use thinkPHP to update data: [Original] and thinkphp. Using thinkPHP to update data: an example [original]. using thinkphp, we deleted and deleted data in batches in the previous article, in this article, we will update data and use thinkPHP to update data: [Original] and thinkphp.

In the previous article, we deleted and deleted data in batches. in this article, we will update the data.

The first is expectation:

  

After clicking the Modify button, enter the modi.html page and modify it. in this case, the attribute of real name is modified:

Click save:

The above is the implementation result. the specific code is as follows:

First, the code in the view is still:

                   
  

User name:

Real name:

Mobile phone number:

Email:

Time added:

Set password:

Confirm password:

Save

Next is the controller: it should be noted that the value before modification needs to be written here, mainly to facilitate user memo, so you need to make an if branch judgment:

  

Public function modi () {if (IS_POST) {$ adminUsersModel = D ("adminUsers"); $ adminUsersModel-> create (); // var_dump ($ adminUsersModel ); // exit ("created successfully! "); If ($ adminUsersModel-> save () {$ this-> success (" modified successfully ", U (" Admin/User/lists "));} else {$ this-> error ($ adminUsersModel-> getError () ;}} else {$ id = isset ($ _ GET ['id'])? Intval ($ _ GET ['id']): ''; if ($ id ='') {exit ("bad param! Enter id ") ;}$ adminUsersModel = D (" adminUsers "); $ adminUsers = $ adminUsersModel-> find ($ id); // var_dump ($ adminUsers ); $ this-> assign ("adminUsers", $ adminUsers); $ this-> display ();}}

This article is original to the blogger. For more information, add the original website.

Link thinkPHP Reference Manual: http://document.thinkphp1.cn/manual_3_2.html

Digress: Recently, I was very busy. I didn't know how to go to the garden except to check something. today, I went online and found that the garden was not as busy as before. I was a little lost, I don't know what park friends think. anyway, I think that in such a very noisy social environment, I can find a person like garden who can calm down and write a few lines of code, there are not many places to think about life. I hope you can support such a platform and share more things. As a junior, I hope to receive more help from you.

In the previous article, we deleted and deleted data in batches. in this article, we will update the data...

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.