thinkphp注册并写入数据到数据库中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="Keywords" content="" /> <meta name="Description"content="" /> <link rel="shortcut icon" href="__PUBLIC__/images/favicon.ico"> <title>注册</title> <script src="__PUBLIC__/js/jquery-1.7.2.min.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css"/> </head> <body> <div class="reg_box" style="overflow:hidden;"> <div class="reg_header"> <div class="reg_hecont"> <img style="margin-top:20px;" src="__PUBLIC__/images/logo.png"> <span style="float:right;margin-top:48px;">返回首页</span> </div> </div> <div class="reg_cenbox"> <div class="reg_frame"> <div class="reg_yzh"> <span style="font-size:15px;color:#5380BB;">注册</span> <span style="float:right;color:#5380BB;" onclick="javascript:location.href='/Login/Login/'">立即登录</span> <span style="float:right;color:#727272;">已有账户?</span> </div> <form action="" method="POST"> <div class="reg_user" > <div class="reg_ku"> </div> <div class="input_user" > <input id="username" name="username" type="text" placeholder=" 请输入您的登录名(6-20)" value="" style="width:100%;height:32px;border-style:none "/> </div> </div> <div class="live_cell" > <div class="live_ku"> </div> <select class="test" style="width:88%;height:35px;border-style:none;color:#767676;" id="projectno" name="projectno"> <option> 请输入您的所在小区</option> <volist name="cell" id="vo"> <option value="{$vo['id']}">{$vo['name']}</option> </volist> </select> </div> <div class="pwd_input" > <div class="pwd_ku"> </div> <div class="pwd_user" > <input id="password" name="password" type="password" placeholder=" 请输入密码(6到20位数字、字母)" value="" style="width:100%;height:32px;border-style:none "/> </div> </div> <div class="pwd_confirm" > <div class="pwd_con"> </div> <div class="pwd_two" > <input id="paded" name="paded" type="password" placeholder=" 请输入确认密码(6到20位数字、字母)" value="" style="width:100%;height:32px;border-style:none "/> </div> </div> <div class="user_agree"> <span style="vertical-align: middle;"> <input type="checkbox" id="agree" checked="checked"/> <label for="agree"> </label> </span> <span style="color:#585858">我已经阅读并同意遵守</span> <span style="color:#4F73A5">《用户协议》</span> </div> <div class="agree_regi" id="ceshi"> <span style="color:#FFF;font-size:16px">同意并注册</span> </div> <input type="hidden" value="{$phone}" id="phone" name="phone" /> </form> </div> </div> <include File="Public:prompt" /> <!--表单提交注册--> <script type="text/javascript"> $("#ceshi").click(function(){ //alert("1"); if($('#agree').is(':checked')){ var username = $.trim($("#username").val()); var cell = $.trim($("#projectno").val()); var password = $.trim($("#password").val()); var paded = $.trim($("#paded").val()); var phone = $.trim($("#phone").val()); if(username == ""){ NewAlert(2,"请输入您的登录名",null); return false; }else{ var reg = /^\w{6,20}$/; if(!reg.test(username)){ NewAlert(2,"请输入有效的登录名",null); return false; } } if(cell==""){ NewAlert(2,"请输入您的所在小区",null); return false; } if(password==""){ NewAlert(2,"请输入密码",null); return false; }else{ var pass = /^[A-Za-z0-9]{6,20}$/; if(!pass.test(password)){ NewAlert(2,"请输入有效的密码",null); return false; } } if(paded==""){ NewAlert(2,"请输入确认密码",null); return false; }else{ var pass = /^[A-Za-z0-9]{6,20}$/; if(!pass.test(password)){ NewAlert(2,"请输入有效的密码",null); return false; } if(paded!==password){ NewAlert(2,"两次密码输入不一致",null); return false; } } alert(username); var data ={ username:username, cell:cell, password:password, phone:phone }; $.ajax({ type:"POST", url:"{:U('Register/Regnest')}", data:data, success:function(msg){ alert(msg); if(msg==1){ //NewAlert(2,"注册成功,请重新登录",null); location.href='/Login/Login'; } } }); }else{ NewAlert(2,"请勾选我已阅读并同意遵守用户协议",null); return false; } }); </script> <!--登录框变色换图--> <script type="text/javascript"> $(function () { $("#username").focus(function () { $(".reg_user").addClass("user_click"); }).blur(function () { $(".reg_user").removeClass("user_click"); }); }); $(function () { $("#birthday").focus(function () { $(".date_birth").addClass("birth_click"); }).blur(function () { $(".date_birth").removeClass("birth_click"); }); }); $(function () { $("#cell").focus(function () { $(".live_cell").addClass("cell_click"); }).blur(function () { $(".live_cell").removeClass("cell_click"); }); }); $(function () { $("#password").focus(function () { $(".pwd_input").addClass("pwd_click"); }).blur(function () { $(".pwd_input").removeClass("pwd_click"); }); }); $(function () { $("#paded").focus(function () { $(".pwd_confirm").addClass("confirm_click"); }).blur(function () { $(".pwd_confirm").removeClass("confirm_click"); }); }); </script> </div> </body> </html>
后台接收数据并写入数据库:
public function Regnest(){
$project = M("project");
$cell = $project->where(array('status'=>1))->order("id desc")->select();
//var_dump($cell);
$this->assign('cell',$cell);
$phone = I('param.phone');
$this->assign('phone',$phone);
if (IS_AJAX) {
$username = I('param.username');
$cell = I('param.cell');
$password = I('param.password');
$dataList=array(
'phone'=>$phone,
'name'=>$username,
'login_id'=>$username,
'password'=>md5($password),
'projectno'=>$cell,
);
$user = M("cuser");
$result=0;
if($user->add($dataList)){
$result=1;
}
$this->ajaxReturn($result);
exit();
}
$this->display(Regnest);
}