<legend id='cIOqq'><style id='cIOqq'><dir id='cIOqq'><q id='cIOqq'></q></dir></style></legend>
<i id='cIOqq'><tr id='cIOqq'><dt id='cIOqq'><q id='cIOqq'><span id='cIOqq'><b id='cIOqq'><form id='cIOqq'><ins id='cIOqq'></ins><ul id='cIOqq'></ul><sub id='cIOqq'></sub></form><legend id='cIOqq'></legend><bdo id='cIOqq'><pre id='cIOqq'><center id='cIOqq'></center></pre></bdo></b><th id='cIOqq'></th></span></q></dt></tr></i><div id='cIOqq'><tfoot id='cIOqq'></tfoot><dl id='cIOqq'><fieldset id='cIOqq'></fieldset></dl></div>
    • <bdo id='cIOqq'></bdo><ul id='cIOqq'></ul>

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

      1. <tfoot id='cIOqq'></tfoot>

        mysqli_stmt::bind_result(): 绑定变量的数量与 PHP 中准

        时间:2023-07-29

      2. <tfoot id='CczYd'></tfoot>
        1. <legend id='CczYd'><style id='CczYd'><dir id='CczYd'><q id='CczYd'></q></dir></style></legend>

              <tbody id='CczYd'></tbody>

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

              <i id='CczYd'><tr id='CczYd'><dt id='CczYd'><q id='CczYd'><span id='CczYd'><b id='CczYd'><form id='CczYd'><ins id='CczYd'></ins><ul id='CczYd'></ul><sub id='CczYd'></sub></form><legend id='CczYd'></legend><bdo id='CczYd'><pre id='CczYd'><center id='CczYd'></center></pre></bdo></b><th id='CczYd'></th></span></q></dt></tr></i><div id='CczYd'><tfoot id='CczYd'></tfoot><dl id='CczYd'><fieldset id='CczYd'></fieldset></dl></div>
                • <bdo id='CczYd'></bdo><ul id='CczYd'></ul>
                  本文介绍了mysqli_stmt::bind_result(): 绑定变量的数量与 PHP 中准备好的语句中的字段数量不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试进行用户名搜索 [我似乎已经完成并正在工作] 但是当您搜索用户名时,会显示有关该帐户的信息.比如我搜索了virtualAnon,他的名字和first_name等信息就会出现在他的用户名后面.

                  I am trying to do a username search [which I seemingly finished and working as well] but when you've searched for the username, the information about the account will show up. For example, I've searched for virtualAnon, his name and information such as first_name will show up after his username.

                  我试图通过替换 $query = "SELECT username FROM users WHERE username like 来修复它?LIMIT 1"; to $query = "SELECT * FROM users WHERE username like ?LIMIT 1"; 但在我尝试之后,错误

                  I've tried to fix it by replacing $query = "SELECT username FROM users WHERE username like ? LIMIT 1"; to $query = "SELECT * FROM users WHERE username like ? LIMIT 1"; but after I've tried that, the error

                  mysqli_stmt::bind_result(): 绑定变量数量不匹配PHP中准备好的语句中的字段数

                  mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in PHP

                  出现.

                  这是用于获取用户名和数据库的 PHP 文件:

                  <?php
                      if($_GET['keyword'] && !empty($_GET['keyword']))
                      {
                          $conn = mysqli_connect('localhost','root','','loginsecure'); //Connection to my database
                          $keyword = $_GET['keyword'];
                          $search = $_GET['keyword'];
                          $keyword="%$keyword%";
                          $query = "SELECT * FROM users WHERE username like ? LIMIT 1";
                          # When I tried to SELECT *, It gives me the error of: Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in ...fetch.php on line 22
                          $statement = $conn->prepare($query);
                          $statement->bind_param('s',$keyword);
                          $statement->execute();
                          $statement->store_result();
                          if($statement->num_rows() == 0) // so if we have 0 records acc. to keyword display no records found
                          {
                              echo '<div id="item">Sorry, but there is no user "'.$search.'" found in our database :(</div>';
                              $statement->close();
                              $conn->close();
                  
                          }
                          else {
                              $statement->bind_result($name); # There is a error i'm encountering when I try to Select * from the line 8.
                              while ($statement->fetch()) //outputs the records
                              {
                                  echo "<div id='item'><a href="../user/username.php?username=$name">$name</a></div>";
                                  # It supposed to show more information about the user, by using $name['first_name'] or $name['last_name']
                              };
                              $statement->close();
                              $conn->close();
                          };
                      };
                  ?>
                  

                  推荐答案

                  您遇到的问题是 mysqli_stmt::bind_result 将尝试将结果集中的每一列绑定到一个变量.这意味着您需要与列相同数量的变量.如果有两列返回,则需要将它们绑定到两个变量.

                  The problem that you're getting is that mysqli_stmt::bind_result will try to bind each column in the result set to a variable. Which means that you need the same amount of variables as you've got columns. If you've got two columns being returned, you need to bind them to two variables.

                  $statement->bind_result($name);中,你是说只有一列,所以将它绑定到$name" 而您的查询(SELECT * FROM users WHERE username like ? LIMIT 1)正在获取该表的所有列.

                  In $statement->bind_result($name);, you're saying "There's only going to be one column, so bind it to $name" whereas your query (SELECT * FROM users WHERE username like ? LIMIT 1) is fetching all the columns for that table.

                  所以解决方案是在这个实例中只选择你想要的单数列.替换

                  So the solution is to only select the singular column you want in this instance. Replace

                  SELECT name 
                  

                  SELECT *
                  

                  这篇关于mysqli_stmt::bind_result(): 绑定变量的数量与 PHP 中准备好的语句中的字段数量不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:mysqli_prepare() 期望参数 1 是 mysqli 下一篇:对象无法在 MySQLi PHP 中转换为字符串

                  相关文章

                  最新文章

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

                  1. <i id='ScRok'><tr id='ScRok'><dt id='ScRok'><q id='ScRok'><span id='ScRok'><b id='ScRok'><form id='ScRok'><ins id='ScRok'></ins><ul id='ScRok'></ul><sub id='ScRok'></sub></form><legend id='ScRok'></legend><bdo id='ScRok'><pre id='ScRok'><center id='ScRok'></center></pre></bdo></b><th id='ScRok'></th></span></q></dt></tr></i><div id='ScRok'><tfoot id='ScRok'></tfoot><dl id='ScRok'><fieldset id='ScRok'></fieldset></dl></div>
                  2. <legend id='ScRok'><style id='ScRok'><dir id='ScRok'><q id='ScRok'></q></dir></style></legend>
                    1. <tfoot id='ScRok'></tfoot>
                        <bdo id='ScRok'></bdo><ul id='ScRok'></ul>