Home >Backend Development >PHP Tutorial >thinkphp5 - thinkPHP Please tell me how to do this, with the code attached!
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>
This is creat:
<code> public function create() { $use = D('classone'); $use->create(); $use->add(); //上面这些代码,也可能执行失败,执行成功,就执行下面★,执行失败,就执行◆,请问这个怎么写? //★$this->success('插入成功', 'lastRow',2); //◆$this->page(); }</code>
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>
This is creat:
<code> public function create() { $use = D('classone'); $use->create(); $use->add(); //上面这些代码,也可能执行失败,执行成功,就执行下面★,执行失败,就执行◆,请问这个怎么写? //★$this->success('插入成功', 'lastRow',2); //◆$this->page(); }</code>
<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>
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>