Fatal error: Call to a member function prepare() on null

孤街浪徒 提交于 2019-12-04 06:50:47

问题


I'm getting this error and i can't find whats wrong.

I've read through the other posts about this error but none of them seemed to help.

Fatal error: Call to a member function prepare() on null on line 92

        <?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);


?>

回答1:


It looks like your $conn variable is not initilazied. I can't see in the code you've uploaded where you are initializing it..




回答2:


you must remove the ; in SELECT line:

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

into this:

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

And remove the $ sign in select statement if this is a column in table:

$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";


来源:https://stackoverflow.com/questions/43133225/fatal-error-call-to-a-member-function-prepare-on-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!