Search code examples
phpprepared-statement

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


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


?>

Solution

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