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

      • <bdo id='JUR8d'></bdo><ul id='JUR8d'></ul>

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

        “没有为准备好的语句中的参数提供数据"

        时间:2023-07-30
      3. <small id='ds7mr'></small><noframes id='ds7mr'>

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

              <legend id='ds7mr'><style id='ds7mr'><dir id='ds7mr'><q id='ds7mr'></q></dir></style></legend>
              • <bdo id='ds7mr'></bdo><ul id='ds7mr'></ul>
                  本文介绍了“没有为准备好的语句中的参数提供数据"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  所以我正在修改脚本以包含准备好的语句.之前它运行良好,但现在我在脚本运行时收到没有为准备好的语句中的参数提供数据".这里有什么问题?

                  So I am reworking a script to include prepared statements. It was working fine before, but now I am getting "No data supplied for parameters in prepared statement" when the script runs. What is the issue here?

                  <?php
                  require_once("models/config.php");
                  
                  
                  $firstname = htmlspecialchars(trim($_POST['firstname']));
                  $firstname = mysqli_real_escape_string($mysqli, $firstname);
                  $surname = htmlspecialchars(trim($_POST['surname']));
                  $surname = mysqli_real_escape_string($mysqli, $surname);
                  $address = htmlspecialchars(trim($_POST['address']));
                  $address = mysqli_real_escape_string($mysqli, $address);
                  $gender = htmlspecialchars(trim($_POST['gender']));
                  $gender = mysqli_real_escape_string($mysqli, $gender);
                  $city = htmlspecialchars(trim($_POST['city']));
                  $city = mysqli_real_escape_string($mysqli, $city);
                  $province = htmlspecialchars(trim($_POST['province']));
                  $province = mysqli_real_escape_string($mysqli, $province);
                  $phone = htmlspecialchars(trim($_POST['phone']));
                  $phone = mysqli_real_escape_string($mysqli, $phone);
                  $secondphone = htmlspecialchars(trim($_POST['secondphone']));
                  $secondphone = mysqli_real_escape_string($mysqli, $secondphone);
                  $postalcode = htmlspecialchars(trim($_POST['postalcode']));
                  $postalcode = mysqli_real_escape_string($mysqli, $postalcode);
                  $email = htmlspecialchars(trim($_POST['email']));
                  $email = mysqli_real_escape_string($mysqli, $email);
                  $organization = htmlspecialchars(trim($_POST['organization']));
                  $organization = mysqli_real_escape_string($mysqli, $organization);
                  $inriding = htmlspecialchars(trim($_POST['inriding']));
                  $inriding = mysqli_real_escape_string($mysqli, $inriding);
                  $ethnicity = htmlspecialchars(trim($_POST['ethnicity']));
                  $ethnicity = mysqli_real_escape_string($mysqli, $ethnicity);
                  $senior = htmlspecialchars(trim($_POST['senior']));
                  $senior = mysqli_real_escape_string($mysqli, $senior);
                  $student = htmlspecialchars(trim($_POST['student']));
                  $student = mysqli_real_escape_string($mysqli, $student);
                  
                  
                  $order= "INSERT INTO persons (firstname, surname, address, gender, city, province,  postalcode, phone, secondphone, email, organization, inriding, ethnicity, senior, student_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                  $stmt = mysqli_prepare($mysqli, $order);
                  mysqli_stmt_bind_param($stmt, "sssd", $firstname, $surname, $address, $gender, $city, $province, $postalcode, $phone, $secondphone, $email, $organization, $inriding, $ethnicity, $senior, $student);
                  mysqli_stmt_execute($stmt); 
                  echo $stmt->error;
                  
                  $result = mysqli_query($mysqli,$stmt);
                  if ($result === false) {
                  echo "Error entering data! <BR>";
                  echo mysqli_error($mysqli);
                   } else {
                  echo "User $firstname added <BR>";
                   }
                  ?>
                  

                  提前致谢.

                  推荐答案

                  你只绑定了四个参数,通过控制字符串sssd",但是你有很多参数.用mysqli绑定变量时,每个参数需要一个字符,例如:

                  You have only bound four arguments, by the control string "sssd", but you have many parameters. When binding variables with mysqli, you need one character for each parameter, for example:

                  mysqli_stmt_bind_param($stmt, "sssdsssssssssdd", $firstname, $surname, $address, 
                      $gender, $city, $province, $postalcode, $phone, $secondphone, $email, 
                      $organization, $inriding, $ethnicity, $senior, $student);
                  

                  (我假设senior 和student 是整数,并且需要d"代码.)

                  (I'm assuming senior and student are integers, and need the "d" code.)

                  您不需要用 mysqli_real_escape_string() 处理任何变量——这就是使用参数的重点.如果您也进行转义,则会在数据库中的数据中得到文字反斜杠字符.

                  You don't need to treat any of your variables with mysqli_real_escape_string() -- that's the point of using parameters. If you do escaping as well, you'll get literal backslash characters in your data in the database.

                  而且在任何情况下都不需要使用 htmlspecialchars() - 在输出到 HTML 时会使用它,而不是在插入到数据库时使用.您将在数据库中的数据中获得诸如 &amp; 之类的文字序列.

                  And you never need to use htmlspecialchars() in any case - you would use that when outputting to HTML, not when inserting to the database. You're going to get literal sequences like &amp; in your data in the database.

                  下一个错误:

                  可捕获的致命错误:mysqli_stmt 类的对象无法转换为字符串..."

                  "Catchable fatal error: Object of class mysqli_stmt could not be converted to string in..."

                  这是由以下原因造成的:

                  This is caused by the following:

                  $result = mysqli_query($mysqli,$stmt);
                  

                  该函数要求第二个参数是一个字符串,一个新的 SQL 查询.但是您已经准备好该查询,因此您需要以下内容:

                  That function expects the second argument to be a string, a new SQL query. But you've already prepared that query, so you need the following:

                  $result = mysqli_stmt_execute($stmt);
                  

                  这篇关于“没有为准备好的语句中的参数提供数据"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP MySQLi 准备的带有绑定参数的查询是否安全? 下一篇:mysqli 准备语句中带有 fetch_array 的 SELECT 语句

                  相关文章

                  最新文章

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

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

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

                    • <bdo id='FMlV4'></bdo><ul id='FMlV4'></ul>
                  1. <tfoot id='FMlV4'></tfoot>