致命错误:在null上调用成员函数prepare()

时间:2017-03-31 05:43:43

标签: php prepared-statement

我收到此错误,我找不到什么错误。

我已经阅读了有关此错误的其他帖子,但似乎没有任何帮助。

致命错误:在第92行调用null上的成员函数prepare()

        <?php 


  include 'config.php';


   $lengd = $_POST["lengd"];
      $height = $_POST["height"];   
       $width = $_POST["width"];



     $min_lengd = $lengd * 0.9; $max_lengd = $lengd * 1.1;     
              $min_height = $height * 0.9; $max_height= $height * 1.1; 
                 $min_width = $width * 0.9; $max_width= $width * 1.1; 


$sql = "SELECT lengd, height, width FROM filters;

      WHERE $lengd BETWEEN :min_lengd AND :max_lengd

        AND $height BETWEEN :min_height AND :max_height

            AND $width BETWEEN :min_width AND :max_width

             LIMIT 2";

            $params = [
            'min_lengd' => $min_lengd,
               'max_lengd' => $max_lengd,
                  'min_height' => $min_height,
                   'max_height' => $max_height,
                      'min_width' => $min_width,
                        'max_width' => $max_width, ];


  $stmt = $conn->prepare($sql);  // LINE 92
  $stmt->execute($params);


?>

2 个答案:

答案 0 :(得分:2)

你必须删除;在SELECT行中:

$sql = "SELECT lengd, height, width FROM filters;

进入这个:

$sql = "SELECT lengd, height, width FROM filters

如果这是表中的列,则删除select语句中的$ sign:

$sql = "SELECT lengd, height, width FROM filters

      WHERE lengd BETWEEN :min_lengd AND :max_lengd

        AND height BETWEEN :min_height AND :max_height

            AND width BETWEEN :min_width AND :max_width

             LIMIT 2";

答案 1 :(得分:2)

看起来你的$ conn变量没有初始化。我无法在你上传的代码中看到你正在初始化的代码..