国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > ThinkPHP > 正文

ThinkPHP基本的增刪查改操作

2024-09-09 15:20:05
字體:
來源:轉載
供稿:網友

表aoli_user字段:

id   username   password    createtime    createip

aoli/Home/Tpl/default/User/index.html:

  1. <form action="__URL__/add" method="post"> 
  2.   用戶名:<input type="text" name="username" /><br /> 
  3.   密碼:<input type="password" name="password" /><br /> 
  4.   重復密碼:<input type="repassword" name="repassword" /><br /> 
  5.   <input type="submit" value="注冊" /> 
  6. </form> 
  7. <volist name="alist" id="vo"> 
  8.   <li><span>ID:</span>{$vo['id']}<span>用戶名:</span>{$vo['username']}<span>注冊ip:</span>{$vo['createip']}<a href="__URL__/del/id/{$vo['id']}">刪除</a>&nbsp;&nbsp;<a href="__URL__/edit/id/{$vo['id']}">編輯</a></li> 
  9. </volist> 

aoli/Home/Tpl/default/User/edit.html:

  1. <form action="__URL__/update" method="post"> 
  2.   用戶名:<input type="text" name="username" value="{$data['username']}" /><br /> 
  3.   密碼:<input type="password" name="password" value="{$data['password']}" /><br /> 
  4.   IP:<input type="text" name="createip" value="{$data['createip']}" /><br /> 
  5.   時間:<input type="text" name="createtime" value="{$data['createtime']}" /><br /> 
  6.   <input type="hidden" value="{$data['id']}" name="id" /> 
  7.   <input type="submit" value="更新" /> 
  8. </form> 

aoli/Home/Lib/Action/UserAction.class.php:

  1. class UserAction extends Action { 
  2.      function index(){ 
  3.          $user=M('user'); 
  4.          $list=$user->field(array('id','username','createip'))->select(); 
  5.          $this->assign('title','thinkphp視頻演示'); 
  6.          $this->assign('alist',$list); 
  7.          $this->display();          
  8.      } 
  9.      //刪除 
  10.      function del(){ 
  11.          $user=D('user'); 
  12.          if($user->delete($_GET['id'])){ 
  13.              $this->success('刪除成功');      
  14.          }else
  15.              $this->error('刪除失敗'); 
  16.          } 
  17.      } 
  18.      //增加 
  19.      function add(){ 
  20.          Load('extend'); 
  21.          if($_POST['password']!=$_POST['repassword']){ 
  22.              $this->error('兩次密碼不一致');      
  23.          } 
  24.          $user=D('user'); 
  25.          if($vo=$user->create()){ 
  26.              $user->password=md5($user->password); 
  27.              $user->createtime=time(); 
  28.              //$user->createip=$_SERVER[]; 
  29.              $user->createip=get_client_ip(); 
  30.              if($user->add()){ 
  31.                  $this->success('用戶注冊成功,返回上級頁面');      
  32.              }else
  33.                  $this->error('用戶注冊失敗,返回上級頁面'); 
  34.              } 
  35.          }else
  36.              $this->error($user->getError());      
  37.          } 
  38.      } 
  39.      //顯示用戶的修改項 
  40.      function edit(){ 
  41.          $user=M('user'); 
  42.          $id=(int)$_GET['id']; 
  43.          $list=$user->where("id=$id")->find(); 
  44.          $this->assign('data',$list); 
  45.          $this->assign('title','顯示用戶編輯信息');  
  46.          $this->display(); 
  47.      } 
  48.      //將更新數據寫入數據庫 
  49.      function update(){ 
  50.          $user=M('user'); 
  51.          $user->password=md5($user->password); 
  52.          if($user->create()){ 
  53.              if($insertid=$user->save()){ 
  54.                  $this->success('更新成功,受影響的行數為'.$insertid); 
  55.              }else
  56.                  $this->error('更新失敗');      
  57.              } 
  58.                        
  59.          } 
  60.      } 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 贵州省| 莱芜市| 天门市| 孝感市| 炉霍县| 泸定县| 临漳县| 河津市| 定陶县| 铜川市| 涿鹿县| 农安县| 南投市| 大名县| 陵水| 奈曼旗| 上饶县| 文昌市| 大足县| 静宁县| 浪卡子县| 东宁县| 民勤县| 嘉定区| 彭阳县| 望城县| 探索| 大悟县| 千阳县| 浮山县| 乌拉特前旗| 辽阳县| 南阳市| 格尔木市| 沁源县| 长汀县| 花莲县| 鄂伦春自治旗| 车险| 开平市| 金坛市|