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

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

    <legend id='xoZ93'><style id='xoZ93'><dir id='xoZ93'><q id='xoZ93'></q></dir></style></legend>

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

        使用准备好的语句检查电子邮件是否已经在数据

        时间:2023-07-30

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

              <legend id='mHQFY'><style id='mHQFY'><dir id='mHQFY'><q id='mHQFY'></q></dir></style></legend>

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

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

                    <tbody id='mHQFY'></tbody>
                • 本文介绍了使用准备好的语句检查电子邮件是否已经在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试将我的代码更改为来自 mysql 的 msqli 准备语句.我不确定如何调整我目前可以检查数据库中是否已有电子邮件的代码.以下是我目前正在使用的有效代码.如何将其更改为准备好的语句并获得相同的结果?

                  I am trying to change my code to msqli prepared statements from mysql. I am not sure how to adapt my code that currently works to check if there is an email already in the database. Below is the code I am currently using that works. How do I change this into a prepared statement and get the same result?

                  //if email is equal to an email already in the database, display an error message
                  
                  if(mysql_num_rows(mysql_query("SELECT * FROM users WHERE email = '".mysql_real_escape_string($_POST['email'])."'")))
                  {
                    echo "<p class='red'>Email is already registered with us</p>";
                  } else {
                    // missing code?
                  }
                  

                  推荐答案

                  应该是这样的:

                  // enable error reporting for mysqli
                  mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
                  // create mysqli object
                  $mysqli = new mysqli(/* fill in your connection info here */);
                  
                  $email = $_POST['email']; // might want to validate and sanitize this first before passing to database...
                  
                  // set query
                  $query = "SELECT COUNT(*) FROM users WHERE email = ?";
                  
                  // prepare the query, bind the variable and execute
                  $stmt = $mysqli->prepare($query);
                  $stmt->bind_param('s', $email);
                  $stmt->execute();
                  
                  // grab the result
                  $stmt->bind_result($numRows);
                  $stmt->fetch();
                  
                  if ($numRows) {
                      echo "<p class='red'>Email is already registered with us</p>";
                  } else {
                      // ....
                  }
                  

                  此链接也可能对您有所帮助:

                  This link may help you as well:

                  http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php

                  这篇关于使用准备好的语句检查电子邮件是否已经在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:mysqli::get_result 有什么问题? 下一篇:何时调用 mysqli::close

                  相关文章

                  最新文章

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

                      • <bdo id='y7RNl'></bdo><ul id='y7RNl'></ul>
                      <legend id='y7RNl'><style id='y7RNl'><dir id='y7RNl'><q id='y7RNl'></q></dir></style></legend>

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

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