HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Wanna tell her - interactive DHTML</title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
</style>
<body>
<form class="form-horizontal" role="form" action="{:url('/useradd')}" method="post">
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">名字</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="firstname" placeholder="请输入名字" name = "name">
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">姓</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="lastname" placeholder="请输入姓" name="xing">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox">请记住我
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">提交信息</button>
</div>
</div>
</form>
</body>
</html>
PHP:
<?php
namespace app\index\controller;
use think\Controller;
use think\View;
use think\Request;
use think\Db;
class Index extends Controller
{
public function useradd(Request $request){
//判断是否有post提交request()->isPost()
if(request()->isPost()){
$data = $request->post();
var_dump($data);
$res = Db::table("users")->insert($data);
if($res){
return "666";
}else{
$this->success("NO","useradd");
}
}else{
//没有post提交,调取添加页面
return view();
}
}
}
如果是多条数据入库可用insertAll()方法,insertAll 方法添加数据成功返回添加成功的条数
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。