Use ThinkPHP framework to implement user information query, update and delete functions

不言
Release: 2023-03-30 17:20:01
Original
1546 people have browsed it

This article mainly introduces the ThinkPHP framework to implement user information query, update and delete functions, and analyzes the database configuration, control and template calling of thinkPHP framework to implement information query, update, delete and other functions in the form of examples. Friends in need You can refer to the following example

This article describes how the ThinkPHP framework implements user information query, update and delete functions. Share it with everyone for your reference, the details are as follows:

One code

1. Configuration file

 false,    // 关闭调试模式
  'DB_TYPE'=> 'mysql',    // 数据库类型
  'DB_HOST'=> 'localhost',   // 数据库服务器地址
  'DB_NAME'=>'db_database30',     // 数据库名称
  'DB_USER'=>'root',      // 数据库用户名
  'DB_PWD'=>'root',        // 数据库密码
  'DB_PORT'=>'3306',      // 数据库端口
  'DB_PREFIX'=>'think_',    // 数据表前缀
);
?>
Copy after login

2. Entry file

Copy after login

3.Controller file

order('id desc')->limit(10)->select();
    $this->assign('select',$select);       // 模板变量赋值
    $this->display();              // 指定模板页
  }
  public function update(){
    $db = M('User');              // 实例化模型类,参数数据表名称,不包含前缀
    $select = $db->where('id='.$_GET['id'])->select();
    $this->assign('select',$select);       // 模板变量赋值
    $this->display(update);             // 指定模板页
    if(isset($_POST['id'])){
      $data['user'] = $_POST['user'];       // 要修改的数据对象属性赋值
      $data['pass'] = md5($_POST['pass']);
      $data['address'] = $_POST['address'];
      $result=$db->where('id='.$_POST['id'])->save($data);   // 根据条件保存修改的数据
      if($result){
        $this->redirect('Index/index','', 2,'数据更新成功');    //页面重定向
      }
    }
  }
  public function delete(){
    $db = M('User');              // 实例化模型类,参数数据表名称,不包含前缀
    $result=$db->where('id='.$_GET['id'])->delete();   // 删除id为5的用户数据
    if($result){
      $this->redirect('Index/index','', 2,'数据删除成功');    //页面重定向
    }
  }
}
?>
Copy after login

4. Template file one





用户信息输出


用户信息
ID 名称 地址 操作
{$user.id} {$user.user} {$user.address} 更新/删除
Copy after login

5. Template file two





用户信息输出


用户信息
名称:
密码:
地址:
Copy after login

Second running results

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

ThinkPHP query statements and usage of related queries

ThinkPHP3.2.3 verification code display and Refresh and verify

Query language commonly used in ThinkPHP

The above is the detailed content of Use ThinkPHP framework to implement user information query, update and delete functions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!