Using thinkphp framework to realize user information query and update delete function

Source: Internet
Author: User
This article mainly introduced the thinkphp framework realizes the user information query update and the deletion function, combined with the instance form analysis the thinkphp framework database configuration, the control and the template call realizes the information inquiry, the update, the deletion and so on the function related operation skill, needs the friend to consult under

This paper describes the thinkphp framework to implement User information query update and delete function. Share to everyone for your reference, as follows:

A code

1. Configuration files

<?phpreturn Array (  ' app_debug ' = False,    //Off debug mode  ' db_type ' = ' mysql ',    //database type  ' Db_ HOST ' + ' localhost ',   //database server address  ' db_name ' = ' db_database30 ',     //Database name  ' Db_user ' + ' root ' ,      //database user name  ' db_pwd ' + ' root ',        //Database Password  ' db_port ' = ' 3306 ',      //Database Port  ' db_ PREFIX ' = ' think_ ',    //data table prefix);? >

2. Entry file

<?phpdefine (' Think_path ', ' ... /thinkphp ');    Define the thinkphp frame path (relative to the entry file) define (' App_name ', ' APP ');       Define the project name define (' App_path ', './app ');        Define the project path require (Think_path. /thinkphp.php ");  Load Frame Entry file App::run ();               Instantiate a site application instance?>

3. Controller files

<?phpheader ("content-type:text/html;  Charset=utf-8 ");              Set page encoding format class Indexaction extends action{public Function index () {$db = M (' User ');    Instantiate the model class, the parameter data table name, which does not contain a prefix $select = $db->order (' id desc ')->limit ()->select ();       $this->assign (' select ', $select);              The template variable is assigned a value $this->display ();              Specify template page} public Function Update () {$db = M (' User ');    Instantiate the model class, parameter data table name, without prefix $select = $db->where (' id= '. $_get[' id ')->select ();       $this->assign (' select ', $select);             Template variable Assignment $this->display (update);       Specify the template page if (isset ($_post[' id ')) {$data [' user '] = $_post[' user '];      Assignment of the data object property to be modified $data [' pass '] = MD5 ($_post[' pass ');      $data [' address '] = $_post[' address '];   $result = $db->where (' id= '. $_post[' id ')->save ($data);    Save modified data according to conditions if ($result) {$this->redirect (' Index/index ', ' ', 2, ' Data Update succeeded '); Page redirection}}} public function Delete () {$db = M (' UsEr ');   Instantiate the model class, parameter data table name, without prefix $result = $db->where (' id= '. $_get[' id ')->delete ();    Delete user data with ID 5 if ($result) {$this->redirect (' Index/index ', ' ', 2, ' data deletion succeeded '); Page redirection}}}?>

4, template file one

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

5. template file Two

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Two running results

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.