thinkphp Implementation Update Data Example (demo) _php instance

Source: Internet
Author: User
Tags add time button type

Before we introduce the text, we introduce the consistent operation methods supported by the data Update method are:

In the previous article we implemented the data deletion and the bulk deletion, this article we will implement the data update.

  The first is still the expected effect chart:

  

Click Modify to enter the Modi.html page , and then modify it so that the real name of the property is modified:

Click to Save:

The above is the effect to implement, the following is the implementation of the specific code:

The first is still the code in the view:

<form role= "form" method= "POST" action= "__module__/admin/user/doadd" > <div class= "Input-group" > <span class= "Input-group-addon" >  Households  Name:</span> <input type=" text "class=" Form-control "placeholder=" "name=" username "> </div> <div class=" Input-group "> <span class=" Input-group-addon "for=" inputWarning1 "> real name:</span> <input type=" text "class=" Form-control "placeholder = "" id= "input" name= "Realname" > </div> <div class= "Input-group" > <span class= "Input-group-addon"
> Mobile number:</span> <input type= "text" class= "Form-control" placeholder= "" Name= "Telphone" > </div> <div class= "Input-group" > <span class= "Input-group-addon" > E-Mailbox:</span> <input type= "Text" class = "Form-control" placeholder= "" name= "email" > </div> <div class= "Input-grou"P "> <span class=" Input-group-addon "> Add time:</span> <input type=" text "class=" Form-control " Placeholder= "2014-05-22" name= "Resgistertime" > </div> <div class= "Input-group" > <span class= " Input-group-addon "> Set password:</span> <input type=" text "class=" Form-control "placeholder=" 123456 "Name="
Password "> </div> <div class=" Input-group "> <span class=" input-group-addon "> Confirm password:</span> <input type= "text" class= "Form-control" placeholder= "123456" name= "Repassword" > </div> <div class= " Input-group "> <button type=" Submit "class=" Btn btn-primary ">    guaranteed  Save   </button> </div> </form>

Next is the controller: it needs to be explained that there is a need to write an unmodified value here, primarily to make it easier for users to remember, and therefore need to be judged by an if branch:

Public Function Modi () {
if (is_post) {
$adminUsersModel = D ("Adminusers");
$adminUsersModel->create ();
Var_dump ($adminUsersModel);
Exit ("Create success!") ");
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! Please enter ID ");
}
$adminUsersModel =d ("Adminusers");
$adminUsers = $adminUsersModel->find ($id);
Var_dump ($adminUsers);
$this->assign ("Adminusers", $adminUsers);
$this->display ();
}

Here are five ways to update the database under thinkphp

The first method:

$ model->where (' id=1 ')->save ($data);

The second method:

$ model->where (' id=1 ')->data ($data)->save ();

The third method:

$ model->create ();

$ model->save ();

The form must contain a hidden field with the primary key name

The fourth method:

$ model->where (' id=5 ')->setfield (' name ', ' thinkphp ');

$ model->where (' id=5 ')->setfield (Array (' name ', ' email '), array (' TP ', ' TP@163.com '));

The fourth method, pass the array time, I can not achieve ...

The Fifth method:

$ model->setinc (' score ', ' id=5 ', 3); Integral plus 3

$ model->setinc (' score ', ' id=5 '); Integral plus 1

$ model->setdec (' score ', ' id=5 ', 5); Points minus 5

$ model->setdec (' score ', ' id=5 '); Points minus 1

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.