SQL语句参数与我的变量匹配,但我不断收到错误信息

时间:2018-12-11 00:57:30

标签: php mysql

下面是我的脚本,当用户在搜索栏中输入信息并单击“提交”按钮时执行。我一直收到错误“警告:mysqli_stmt_bind_param():变量数与准备好的语句中的参数数不匹配” 。变量和值的数量相等,但我不断收到此错误。任何帮助将不胜感激,谢谢!

我还包括了当前数据库表here的图片

  include_once 'dbh-inc.php';

    if (isset($_POST['submit-search'])) {

      $search = $_POST['search'];

      $sql = "SELECT * FROM animals WHERE animal_animaltype LIKE '%?%' OR animal_breed LIKE '%?%' OR descGallery LIKE '%?%'";

      $stmt = mysqli_stmt_init($conn);
      if (!mysqli_stmt_prepare($stmt, $sql)) {
            echo "SQL error";
        } else {
            mysqli_stmt_bind_param($stmt, "sss", $search, $search, $search);
            mysqli_stmt_execute($stmt);
            $result = mysqli_stmt_get_result($stmt);
        $resultCount = mysqli_num_rows($result);

        if ($resultCount > 0) {
          echo "There are ".$resultCount." results for your search";
          while ($row = mysqli_fetch_assoc($result)) {
              echo '<a href="#">
              <div style="background-image: url(img/gallery/'.$row["imgFullNameGallery"].');"></div>
              <h3>'.$row["animal_name"].'</h3>
              <h3>'.$row["animal_breed"].'</h3>
              <p>'.$row["descGallery"].'</p>
              <br>
              <h1>'.'Current owner: '.$row["animal_owner"].'</h1>  
            </a>';
          }
        }
        }
    }

1 个答案:

答案 0 :(得分:1)

从查询中删除'ss',并将const formGroup = new FormGroup({ test: new FormArray([ new FormGroup({ fr: new FormControl('') }) ]) }) formGroup.get('test').at(0).get('fr').patchValue(oldFr) 添加到变量'%%'

%%