• <small id='RL3Bo'></small><noframes id='RL3Bo'>

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

        如何使用 MySQLi 在 PHP 中获取数据?

        时间:2023-07-30
          <tbody id='rFdUQ'></tbody>
          <i id='rFdUQ'><tr id='rFdUQ'><dt id='rFdUQ'><q id='rFdUQ'><span id='rFdUQ'><b id='rFdUQ'><form id='rFdUQ'><ins id='rFdUQ'></ins><ul id='rFdUQ'></ul><sub id='rFdUQ'></sub></form><legend id='rFdUQ'></legend><bdo id='rFdUQ'><pre id='rFdUQ'><center id='rFdUQ'></center></pre></bdo></b><th id='rFdUQ'></th></span></q></dt></tr></i><div id='rFdUQ'><tfoot id='rFdUQ'></tfoot><dl id='rFdUQ'><fieldset id='rFdUQ'></fieldset></dl></div>

        • <legend id='rFdUQ'><style id='rFdUQ'><dir id='rFdUQ'><q id='rFdUQ'></q></dir></style></legend>

          <tfoot id='rFdUQ'></tfoot>

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

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

                  本文介绍了如何使用 MySQLi 在 PHP 中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试了多次,但无法成功获得正确的语法——根据 PHP 5.5.12——从我的数据库中获取单行或多行.

                  I tried several times but cannot succeed in getting the right syntax—according to PHP 5.5.12 —to fetch single or multiple rows from my database.

                  session_start();
                  $con=mysqli_connect("localhost","root","","doortolearn");
                  if (!$con) {
                      echo "Could not connect to DBMS";       
                  }
                      $query="select * from teacher where tremail='$_POST[email]' and trpasssword='$_POST[password]'";
                      $result=mysqli_query($con,$query);
                      $flag=FALSE;
                      while ($row=mysqli_fetch_array($result,MYSQLI_BOTH)) {
                          $_SESSION['email']=$row['email'];
                          $flag=TRUE;
                      }
                  

                  推荐答案

                  首先,$_POST[password]周围没有单引号':

                  First, you have no single quotes ' around $_POST[password]:

                  $query = "SELECT * FROM teacher WHERE tremail='". $_POST['email'] ."' and trpasssword='" . $_POST['password'] . "'";
                  $result = mysqli_query($con, $query) or die(mysqli_error($con));
                  $flag = FALSE;
                  while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
                      $_SESSION['email'] = $row['email'];
                      $flag = TRUE;
                  }
                  

                  但除此之外,您是否甚至在此处设置了 MySQL 数据库连接?我看到 $con 但这真的有效吗?

                  But past that, do you even have a MySQL database connection set here? I see $con but is that really working?

                  此外,通过将 或 die(mysql_error($con)) 添加到您的 mysqli_query($con, $query) 行来检查是否存在错误.

                  Also, check if there are errors by adding or die(mysql_error($con)) to your mysqli_query($con, $query) line.

                  此外,您有一个 $_SESSION 值,但您是否在脚本的开头设置了 session_start?

                  Also, you have a $_SESSION value, but do you even set session_start at the beginning of your script?

                  但我也建议您使用 mysqli_stmt_bind_param 作为您的值,如果您不打算进行基本验证,至少可以将它们转义:

                  But I also recommend you use mysqli_stmt_bind_param for your values to at least escape them if you are not going to do basic validation:

                  $query = "SELECT * FROM teacher WHERE tremail=? and trpasssword=?";
                  mysqli_stmt_bind_param($query, 'ss', $_POST['email'], $_POST['password']);
                  $result = mysqli_query($con, $query) or die(mysqli_error($con));
                  $flag = FALSE;
                  while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
                      $_SESSION['email'] = $row['email'];
                      $flag = TRUE;
                  }
                  

                  这篇关于如何使用 MySQLi 在 PHP 中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Mysqli 查询不能工作两次 下一篇:使用 MySQLi 的 SUM 的单个结果

                  相关文章

                  最新文章

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

                      <i id='kAHJ6'><tr id='kAHJ6'><dt id='kAHJ6'><q id='kAHJ6'><span id='kAHJ6'><b id='kAHJ6'><form id='kAHJ6'><ins id='kAHJ6'></ins><ul id='kAHJ6'></ul><sub id='kAHJ6'></sub></form><legend id='kAHJ6'></legend><bdo id='kAHJ6'><pre id='kAHJ6'><center id='kAHJ6'></center></pre></bdo></b><th id='kAHJ6'></th></span></q></dt></tr></i><div id='kAHJ6'><tfoot id='kAHJ6'></tfoot><dl id='kAHJ6'><fieldset id='kAHJ6'></fieldset></dl></div>
                        <bdo id='kAHJ6'></bdo><ul id='kAHJ6'></ul>
                    1. <small id='kAHJ6'></small><noframes id='kAHJ6'>