<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ![](https://box.kancloud.cn/499db9463a8836aadb3be8c340e52c9b_613x55.png)首先建立一張注冊用的數據表先,我這里新建了一張wemall_name表 里面數據大概是id username,password這幾個,后期不一定會用到這張表,只能用來測試用的,因為還有很多字段沒有建好,一開始沒有設計數據庫就會有一些后期的麻煩,無可避免的。 建好表之后就是控制器代碼的實現了。 ![](https://box.kancloud.cn/0d3d762bebbb14beec55c04d66e6d773_560x255.png) 前端頁面代碼app/index/view/register.html: ~~~ <!DOCTYPE html> <html> <head> <title>注冊頁面</title> <meta charset="utf-8"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-touch-fullscreen" content="yes"> <meta http-equiv="Access-Control-Allow-Origin" content="*"> <link href="__INDEX__/css/register.css" type="text/css" rel="stylesheet"> <link href="__INDEX__/css/global.css" type="text/css" rel="stylesheet"> <script type="text/javascript" src="__INDEX__/js/register.js"></script> </head> <body> <div id="layout"> <span>賬號注冊</span> <form method="post" action="{:url('index/login/register')}"> <ul> <p id="err_msg"></p> <li><i class="un"><img src="__INDEX__/images/user_name.png"></i><input class="username" type="text" id="username" name="username" value="{$Request.session.username}" placeholder="請輸入用戶名" onblur="checkusernamea()" /></li> <div id="yhm"><p id="check1" style="color: red; font-size: 15px; text-align: center;"></p></div> <li><i class="pw"><img src="__INDEX__/images/pwd.png"></i><input class="pwd" type="password" name="cpassword" id="cpassword" placeholder="請輸入密碼" onblur="checkpassword(this.value)"/></li> <div id="yhm1"><p id="checkPasswordResult" style="color: red; font-size: 15px; text-align: center;"></p></div> <li><i class="pw2"><img src="__INDEX__/images/pwd.png"></i><input class="pwd2" type="password" id="passwordd" name="passwordd" placeholder="請輸入確認密碼" onblur="checkpasswordd()" /></li> <div id="yhm2"><p id="check3" style="color: red; font-size: 15px; text-align: center;"></p></div> <div class="queren"><input class="fx" type="checkbox" checked="checked" /><p>我已閱讀并同意《用戶協議》</p></div> </ul> <div class="reg_btn"> <button class="submit" type="submit" onclick="return checkform(this.form);">注冊</button> <a href="{:url('index/login/index')}"><div class="reg-login"><p>已有帳號,立即登陸</p></div></a> </div> </form> </div> </body> </html> ~~~ 還有一些其他鏈接控制器的方法: ![](https://box.kancloud.cn/712a73ae8a966b29ea19eb4bd31eade8_953x683.png) 還有一個就是我使用了ajax的異步刷新來實現用戶名檢測: ![](https://box.kancloud.cn/c4eba1d1fcd94892e16ef69188659f7b_932x243.png) 控制器ajax代碼: ![](https://box.kancloud.cn/9ec734304a97115f3a5a0c96be68b6f5_610x243.png) ![](https://box.kancloud.cn/d1f8308800893fa71078c655bf5232bb_684x81.png) 下面到注冊代碼了,在這個功能上我研究了幾天(當然更多的因為我去追劇了 * _ *),看了好幾份代碼,最后發現,手冊里早已經寫好了方法,雖然耗費了些時間,但是也了解了一些其他方面的東西,還是有些許收獲的。也能夠了解到多種解決方法。 控制器app/index/login.php代碼: ~~~ <?php /** * Created by PhpStorm. * User: Administrator * Date: 2017/5/14 * Time: 22:44 */ namespace app\index\controller; use think\Controller; use think\Db; use think\Cookie; use think\Request; use think\Session; class Login extends Controller{ public function index(){ return $this->fetch('login'); } public function regi(){ return $this->fetch('register'); } public function register(){ //檢查數據庫名 $userinfo = Db::name('name'); //判斷是否post輸入 if (input('post.')){ //實例輸入獲取 $data=input('post.'); //驗證用戶信息 if (!isset($data['username']) || empty($data['username'])){ return $this->erro('請輸入用戶名!'); } if (!isset($data['cpassword']) || empty($data['cpassword'])){ return $this->error('請輸入密碼',-1); } if (!isset($data['passwordd']) || empty($data['passwordd'])){ return $this->error('請確認密碼',-1); } if ($data['cpassword'] != $data['passwordd']){ return $this->error('兩次密碼不一致',-1); } } //接收post數據 $username = input('post.username'); $password = input('post.cpassword'); $repassword = input('post.passwordd'); //獲取數據并生成數組 $value['username'] = $username; $value['password'] = $password; //插入數據 $res = $userinfo->insert($value); //插入數據 //$data=input('post.'); //$ids = $userinfo->insert($usss); //插入數據id //$ids = $userinfo->insertGetId($data); //插入數據 //$idss = $userinfo->insert($data); //$newdata['id'] = $ids; //$newdata['username'] = $idss; //$aaa = Request::instance(); //$bbb = $aaa->post("cpassword"); //$ids = $userinfo->insert($bbb); //$newdata['cpassword'] = $ids; //$dataa = $this->request->post('username'); //$datab = $this->request->post('cpassword'); //$ids = $userinfo->insert($dataa); //$ids = $userinfo->insert($datab); //$newdata['username'] = $ids; //$newdata['password'] = $idsb; //$newids = $userinfo->update($res); //進行判斷 if ($res){ //$__SESSION['id'] = $ids; //記錄到session中 Session::set('username'); return $this->success('注冊成功',url('index/login/index')); }else{ return $this->error('注冊失敗'); } //記錄用戶登錄信息 //cookie('id',$has['id'],7200); //cookie('username',$has['username'],7200); //跳轉登錄 } //判斷用戶名是否已經存在 public function check($username) { $info = db('name')->where('username','=',$username)->find(); if ($info){ echo "用戶名已存在"; }else{ echo ""; } exit; } } /*//插入數據 //判斷是否post輸入 * if (request()->isPost()) { * //鏈接數據庫名 $userinfo = Db::name('name'); $data = input('post.'); $res = $userinfo->insert($data); if ($res) { return $this->success('注冊成功'); } else { return $this->success('注冊失敗'); } } */ ~~~ 在表單提交這方面花費了一些功夫,雖然最后解決了,但是我還是不能太滿意,我覺得有更好的方法來解決,可惜技術不到家。 其他的注冊插入數據方法我也一起截圖進來吧。 這是我參考的其中一份代碼: ![](https://box.kancloud.cn/c8fb13e9ecc201ee9b50bbf0ca59d8aa_663x811.png) 這個也是注冊方法 ![](https://box.kancloud.cn/b4f55b4d4fec9afca5abbabe94835c5a_498x399.png) 注冊跳轉頁面: ![](https://box.kancloud.cn/75117a61632c6f5a4bfb8b8d9a73da95_351x254.png) ![](https://box.kancloud.cn/4b82eba878016cb2cbcc011eb8d71566_379x20.png) 下面將會實現一些功能,比如用戶名判斷是否存在,雖然ajax實現了但是控制器還需要再驗證一次,還有就是用戶名長度問題,使用session記錄登錄用戶信息功能的實現。 在app/index/login.php/sutr方法中添加判斷條件(上面使用的register方法修改成了sutr,并在注冊頁面url里修改好方法名),通過查詢數據庫數據來實現驗證用戶名是否存在與用戶名的長度。 ![](https://box.kancloud.cn/ea9fc24b7aefc739c0ada5a1351d8434_690x551.png) 使用session記錄注冊的用戶名 在config配置里找到session開啟并在類中引用use think\Session ![](https://box.kancloud.cn/9942c67d8e04c043cb38b73b09fc5068_534x266.png) 記錄session,賦值給session中,第一個填寫前端頁面的表單名字,第二個寫的是接受到表單post數據的變量名。 ![](https://box.kancloud.cn/499db9463a8836aadb3be8c340e52c9b_613x55.png) 在頁面中引入value,這里的意思是引用session保存的用戶名。 ![](https://box.kancloud.cn/261bffebfcc2584b7865eade3337f6f9_923x144.png) 到這里基本已經完成了注冊功能的實現,下一節將會講到我這次遇到的新函數和方法,基本上了解完這些也算是學會新增數據了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看