ThinkPHP表单操作(未加验证)

FormController.class.php

<?php    
namespace HomeController;
use ThinkController;
class FormController extends Controller{
    
    //用户登录页面
    public function login_ac(){
        
        if(empty($_POST))
        {
            $this->display();
        }
        else
        {
                
            $user = D('user');
            
            $ttt = array('uid'=>I('uid'),'pwd'=>I('pwd'));
            
             $data = $user->where($ttt)->count();
             
            if($data == 1)
            {
                $this->success('登陆成功!','main');
            }
            else
            {
                $this->error('登陆失败!账号或密码错误');
            }   
        }
        
    }

    //信息显示页面
    public function main_ac(){
        
        $user = D('user');
        
        $arr = $user->select();
        
        $this->assign('arr',$arr);
        
        $this->display();
        
    }
    
    // 用户注册页面
    public function add_ac(){
        
            if(empty($_POST))
        {
            $this->display();
        }
            else
        {
            $user = D('user');
            
            $user->create();
            
            $result = $user->add();
            
                if($result)
            {
                $this->success('注册成功','login');
            }
                else
            {
                $this->error('注册失败');
            }
        }
    }
        
    //修改信息页面
    public function update_ac(){
        
        $ids = I('get.ids');
        
        $user = D('user');
        
            //显示修改的数据
            if(empty($_POST))
        {
            $info = $user->find($ids);
            
            $this->assign('info',$info);
            
            $this->display();
        }
        
            else
        {
            //修改数据操作
            $user->create();
            
            $result = $user->save();
            
                if($result)
            {
                $this->success('修改成功','main');
            }
                else
            {
                $this->error('修改失败');
            }
        }                    
        
    }
    
    public function delete_ac(){
        
        $ids = I('ids');
        
        $user = D('user');
        
        $result = $user->delete($ids);
        
        if($result)
        {
            $this->success('删除成功','main');
        }
        else
        {
            $this->error('删除失败');
        }
    }

}
        

?>
View Code

login.html登陆页面模板

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆页面</title>
</head>
<body>
<form action='__SELF__' method='post'>

<div>用户名:<input type='text' name='uid'/></div></br>

<div>密码:&nbsp;<input type='text' name='pwd'/></div></br>

<input type='submit'  value='登陆'/>

<a href='__CONTROLLER__/add'>注册账号</a>

</form>

</body>
</html>
View Code

main.html信息展示页面模板

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>显示页面</title>
</head>
<body>
<h1>主界面</h1>
<table cellpadding='0' cellspacing='0' border='1' width=100%>
<tr>
<td>用户名</td><td>密码</td><td>邮箱</td><td>手机</td><td>身份证号</td><td>操作</td>
</tr>

<foreach name = 'arr' item = 'vo'>
<tr>
<td><{$vo.uid}></td>
<td><{$vo.pwd}></td>
<td><{$vo.mail}></td>
<td><{$vo.tel}></td>
<td><{$vo.id}></td>
<td>
<a href="__CONTROLLER__/update?ids=<{$vo.ids}>">修改</a>
<a href="__CONTROLLER__/delete?ids=<{$vo.ids}>">删除</a>
</td>
</tr>
</foreach>

</body>
</html>
View Code

add.html用户注册页面模板

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
</head>
<body>
<h1>注册页面</h1>
<form action="__SELF__"  method="post"/>

<div>用户名:<input type="text" name="uid"/></div></br>

<div>密码:&nbsp;<input type="text" name="pwd"/></div></br>

<div>邮箱:&nbsp;<input type="text" name="mail"/></div></br>

<div>手机号:<input type="text" name="tel"/></div></br>

<div>身份证:<input type="text" name="id"/></div></br>

<input type="submit" value="注册"/>&nbsp;&nbsp;
<a href='__CONTROLLER__/login'>返回登陆</a>

</form>
    
</body>
</html>
View Code

update.html信息修改页面模板

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改页面</title>
</head>
<body>
<form action='__SELF__'  method='post'>

<input type='hidden' name="ids" value='<{$info.ids}>'/>

<div>用户名:<input type="text" name='uid' value='<{$info.uid}>'/></div></br>

<div>密码:&nbsp;<input type="text" name='pwd' value='<{$info.pwd}>'/></div></br>

<div>邮箱:&nbsp;<input type="text" name='mail' value='<{$info.mail}>'/></div></br>

<div>手机:&nbsp;<input type="text" name='tel' value='<{$info.tel}>'/></div></br>

<div>身份证:<input type="text" name='id' value='<{$info.id}>'/></div></br>

<input type="submit" value='修改'/>&nbsp;&nbsp;

<a href='__CONTROLLER__/main'>回到主页</a>

</form>

</body>
</html>
View Code
原文地址:https://www.cnblogs.com/sihuiming/p/5513521.html