tp5提交留言入库

1,给一个form表单:

2,后台添加方法内编码:

public function add()
    {
        #获取传递过来的变量值
        $username = input('param.username');
        $message = input('param.content');

        if($username != '' && $message != '')
        {
            #插入数据
            $db = db('user');
            $result  = $db -> insert(['username' => $username,'message' => $message]);
            dump($result);
            $this -> success("留言成功!",'bbs/show');
        }
        #$this -> error("留言失败");
        

        return $this -> fetch();
    }

3,插入成功,可到数据库查看新数据:

 

posted @ 2019-01-07 00:53  wong。  阅读(661)  评论(0编辑  收藏  举报