久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='B4JtN'></tfoot>
  • <i id='B4JtN'><tr id='B4JtN'><dt id='B4JtN'><q id='B4JtN'><span id='B4JtN'><b id='B4JtN'><form id='B4JtN'><ins id='B4JtN'></ins><ul id='B4JtN'></ul><sub id='B4JtN'></sub></form><legend id='B4JtN'></legend><bdo id='B4JtN'><pre id='B4JtN'><center id='B4JtN'></center></pre></bdo></b><th id='B4JtN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='B4JtN'><tfoot id='B4JtN'></tfoot><dl id='B4JtN'><fieldset id='B4JtN'></fieldset></dl></div>

    1. <legend id='B4JtN'><style id='B4JtN'><dir id='B4JtN'><q id='B4JtN'></q></dir></style></legend>

      <small id='B4JtN'></small><noframes id='B4JtN'>

          <bdo id='B4JtN'></bdo><ul id='B4JtN'></ul>

        嘗試訪問 bool 類型值的數組偏移量

        Trying to access array offset on value of type bool(嘗試訪問 bool 類型值的數組偏移量)
          <tbody id='KoSZL'></tbody>
          <bdo id='KoSZL'></bdo><ul id='KoSZL'></ul>
        • <legend id='KoSZL'><style id='KoSZL'><dir id='KoSZL'><q id='KoSZL'></q></dir></style></legend>

            • <tfoot id='KoSZL'></tfoot>
            • <i id='KoSZL'><tr id='KoSZL'><dt id='KoSZL'><q id='KoSZL'><span id='KoSZL'><b id='KoSZL'><form id='KoSZL'><ins id='KoSZL'></ins><ul id='KoSZL'></ul><sub id='KoSZL'></sub></form><legend id='KoSZL'></legend><bdo id='KoSZL'><pre id='KoSZL'><center id='KoSZL'></center></pre></bdo></b><th id='KoSZL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='KoSZL'><tfoot id='KoSZL'></tfoot><dl id='KoSZL'><fieldset id='KoSZL'></fieldset></dl></div>

              <small id='KoSZL'></small><noframes id='KoSZL'>

                  本文介紹了嘗試訪問 bool 類型值的數組偏移量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  $query = $pdo -> prepare("SELECT * FROM Users WHERE Username =:Username");
                  $query->bindParam(':Username', $name);
                  $query->execute();
                  
                  $nameRes = $query->fetch(PDO::FETCH_ASSOC);
                  if ($nameRes['Username']==$_POST['username']) {
                      die ("Username is already in use!");
                  }   
                  
                  $query = $pdo -> prepare("SELECT * FROM Users WHERE Email =:Email");
                  $query->bindParam(':Email', $email);
                  $query ->execute();
                  $emailRes = $query->fetch(PDO::FETCH_ASSOC);
                  
                  if ($emailRes['Email']==$_POST['email']) {
                      die ("Email is already in use!");
                  }
                  

                  我在我的應用程序的注冊頁面上有這個代碼,當用戶名可以免費使用但電子郵件不是,反之亦然我得到這個

                  I have this code on the registration page of my app and when Username is free to use but email is not and vice versa I get this

                  注意:嘗試訪問 bool 類型值的數組偏移量

                  Notice: Trying to access array offset on value of type bool

                  好的,結果返回false,但在這種情況下該怎么辦?注意:這是在 php v7.4 上,同樣的事情在 v7.3 上工作

                  Ok the result is returning false but what to do in this situation? Note: This is on php v7.4 this same thing was working on v7.3

                  推薦答案

                  您收到此錯誤可能是因為在數據庫中找不到符合您條件的記錄.

                  解決此錯誤的最簡單方法是先檢查數據庫是否返回任何內容.

                  The easiest way to solve this error is to check if the database returned anything first.

                  $emailRes = $query->fetch(PDO::FETCH_ASSOC);
                  // VVV - Here I am checking if there was anything returned and then I check the condition
                  if($emailRes && $emailRes['Email']==$_POST['email']) {
                      // ...
                  }
                  

                  如果您不在乎數據庫是否返回任何內容,那么您可以簡單地提供一個默認值.例如:

                  If you don't care whether the database returned anything, then you can simply provide a default value. For example:

                  $emailRes = $query->fetch(PDO::FETCH_ASSOC);
                  $email = $emailRes['Email'] ?? ''; // default: empty string
                  

                  使用 PDO 檢查 DB 中是否存在的正確方法是:

                  The correct way to check for existance in DB using PDO is:

                  $query = $pdo->prepare("SELECT COUNT(*) FROM Users WHERE Username =:Username");
                  $query->execute([':Username' => $name]);
                  if ($query->fetchColumn()) {
                      throw new Exception("Username is already in use!");
                  }
                  
                  $query = $pdo->prepare("SELECT COUNT(*) FROM Users WHERE Email =:Email");
                  $query->execute([':Email' => $email]);
                  if ($query->fetchColumn()) {
                      throw new Exception("Email is already in use!");
                  }
                  

                  我沒有在 PHP 中獲取行并再次進行比較,而是從數據庫中獲取匹配行的計數,并將該計數用作 if 語句中的布爾值.fetchColumn() 將從第一行獲取單列,如果我使用 COUNT(*) 我知道總會有一行.

                  Instead of fetching the row and doing the comparison again in PHP I am fetching a count of matching rows from the database and I use that count as a boolean in the if statement. fetchColumn() will fetch a single column from the first row and if I use COUNT(*) I know there will always be one row.

                  您也可以在一個查詢中完成:

                  You can also do it in one query:

                  $query = $pdo->prepare("SELECT COUNT(*) FROM Users WHERE Username =:Username OR  Email =:Email");
                  $query->execute([':Username' => $name, ':Email' => $email]);
                  if ($query->fetchColumn()) {
                      throw new Exception("Username or email is already in use!");
                  }
                  

                  這篇關于嘗試訪問 bool 類型值的數組偏移量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

                  <small id='aH0Z5'></small><noframes id='aH0Z5'>

                  • <tfoot id='aH0Z5'></tfoot>

                    <legend id='aH0Z5'><style id='aH0Z5'><dir id='aH0Z5'><q id='aH0Z5'></q></dir></style></legend>
                        <tbody id='aH0Z5'></tbody>

                        <bdo id='aH0Z5'></bdo><ul id='aH0Z5'></ul>

                          <i id='aH0Z5'><tr id='aH0Z5'><dt id='aH0Z5'><q id='aH0Z5'><span id='aH0Z5'><b id='aH0Z5'><form id='aH0Z5'><ins id='aH0Z5'></ins><ul id='aH0Z5'></ul><sub id='aH0Z5'></sub></form><legend id='aH0Z5'></legend><bdo id='aH0Z5'><pre id='aH0Z5'><center id='aH0Z5'></center></pre></bdo></b><th id='aH0Z5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aH0Z5'><tfoot id='aH0Z5'></tfoot><dl id='aH0Z5'><fieldset id='aH0Z5'></fieldset></dl></div>
                          • 主站蜘蛛池模板: 国产在线h | 国产美女在线看 | 亚洲一区二区视频 | 波多野结衣av中文字幕 | 久久久久国产 | 成人一区二区三区在线观看 | 国产精品一区二区久久精品爱微奶 | 国产精品有限公司 | 免费观看成人性生生活片 | 亚洲精品一区二区在线观看 | 日韩精品一区二区不卡 | 国产成人精品一区二区三区网站观看 | xx性欧美肥妇精品久久久久久 | 91麻豆精品国产91久久久久久 | www.精品国产 | 国产精品美女久久久久久免费 | 日本特黄a级高清免费大片 国产精品久久性 | 激情免费视频 | 伊人中文字幕 | 精品国产一级片 | a黄毛片 | 成人免费小视频 | 日日摸夜夜添夜夜添精品视频 | 精品久久久久久久久亚洲 | 五月天婷婷综合 | 91精品国产91 | 国产精品久久久久久一区二区三区 | 欧美精品一区三区 | 在线看91| 91久久综合 | 亚洲自拍偷拍av | 亚洲播放一区 | 亚洲国产黄 | 国产精品久久久久久久免费大片 | 91国产在线视频在线 | 亚洲第一av网站 | 久久久123| 毛片a级毛片免费播放100 | 欧美日韩网站 | 国产精品a免费一区久久电影 | 一区二区三区在线免费观看 |