Home > Backend Development > PHP Tutorial > thinkphp5 - thinkPHP Please tell me how to do this, with the code attached!

thinkphp5 - thinkPHP Please tell me how to do this, with the code attached!

WBOY
Release: 2016-07-06 13:53:50
Original
1085 people have browsed it

This is the html part:

<code><form name="name" action="http://localhost/yb1/Home/curd/create" method="post">
    <input type="text" name="学号" value="1446298514" id='xh'>
    <input type="submit" name='tj' value="提交">
</form></code>
Copy after login
Copy after login

This is creat:

<code>    public function create()
    {

        $use = D('classone');
        $use->create();
        $use->add();

        //上面这些代码,也可能执行失败,执行成功,就执行下面★,执行失败,就执行◆,请问这个怎么写?
        
        //★$this->success('插入成功', 'lastRow',2);
        //◆$this->page();

    }</code>
Copy after login
Copy after login

Reply content:

This is the html part:

<code><form name="name" action="http://localhost/yb1/Home/curd/create" method="post">
    <input type="text" name="学号" value="1446298514" id='xh'>
    <input type="submit" name='tj' value="提交">
</form></code>
Copy after login
Copy after login

This is creat:

<code>    public function create()
    {

        $use = D('classone');
        $use->create();
        $use->add();

        //上面这些代码,也可能执行失败,执行成功,就执行下面★,执行失败,就执行◆,请问这个怎么写?
        
        //★$this->success('插入成功', 'lastRow',2);
        //◆$this->page();

    }</code>
Copy after login
Copy after login

<code>public function create()
    {

        $use = D('classone');
        if($use->create()){
            if($use->add()){
                $this->success('插入成功', 'lastRow',2);
                
            }else{
                $this->error("插入失败!");
            }
        }else{
            $this->error($use->getError())
        }
    }</code>
Copy after login

First determine whether create is successful. If it fails, return immediately. Then determine whether add is successful. Successfully execute the following. If it fails, give an error message

<code>public function create()
    {

        $use = D('classone');
        $use->create();
        $res=$use->add();
           
        if($res){
            $this->success('插入成功', 'lastRow',2);
        }
        else {
            $this->page();
        }

    }</code>
Copy after login
Related labels:
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template