title: mysqli_free_result() expects parameter 1 to be mysqli_result, null given in
body: <p>I just migrated a site from one domain to another domain (and another host). I made sure that all links were replaced and exported/imported my database. The migration seemed to have worked, but for some reason I am getting an error on my new domain that I did not get on my old domain (with, as far as I know, the same code).</p>
  
  <p>My error is: "Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, null given in <em>path</em> on line 84". I looked at the other StackOverflow questions that address this error, but I have not found a solution yet.</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  session_start();
  
  // 1. Create a database connection
  $dbhost = 
  $dbuser = 
  $dbpass = 
  $dbname = 
  $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  // Test if connection occurred.
  if(mysqli_connect_errno()) {
    die("Database connection failed: " . 
      mysqli_connect_error() .
      " (" . mysqli_connect_errno() . ")"
      );
  }
  
  // 2. Perform database query
  if (empty($_SESSION['order'])) {
      $query = "INSERT INTO `orders` (`order_id`) VALUES (NULL)";
      $result = mysqli_query($connection, $query);
      // Test if there was a query error
      if (!$result) {
      die("Database query failed.");
      }
      // 3. Use returned data (if any)
      $order_id_recent = mysqli_insert_id($connection);
      $_SESSION['order'] = $order_id_recent;
  }
  
  $size = $_POST["size"];
  $paper = $_POST["paper"];
  $type = $_POST["type"];
  $quantity = $_POST["quantity"];
  
  // 2. Perform database query
  $query2 = "SELECT product_id FROM product WHERE product_type = '$type' AND size = '$size' AND paper = '$paper'";
  $result2 = mysqli_query($connection, $query2);
  // Test if there was a query error
  if (!$result2) {
    die("Database query failed.");
  }
  
  // 3. Use returned data (if any)
  while($row = mysqli_fetch_assoc($result2)) {
      $product_id = $row['product_id'];
  }
  
  $order_id = $_SESSION['order'];
  
  // 2. Perform database query
  $order_id = $_SESSION['order'];
  
  $query3 = "SELECT * FROM order_item WHERE order_id = '$order_id' AND product_id = '$product_id'";
  $result3 = mysqli_query($connection, $query3);
  // Test if there was a query error
  if (!$result3) {
    die("Database query failed.");
  }
  
  while($row = mysqli_fetch_assoc($result3)) { 
      $itemexistrows = mysqli_num_rows($result3);
  }
  
  if ($itemexistrows &gt; 0) {
      $query4 = "UPDATE order_item SET quantity = quantity + '$quantity' WHERE product_id = '$product_id' AND order_id = '$order_id'";
      $result4 = mysqli_query($connection, $query4);
      if (!$result4) {
      die("Database query failed.");
      } else {
          echo 'The item has been added to your cart. &lt;a class="text-red" href="viewcart.php"&gt;View your cart&lt;/a&gt;&lt;/div&gt;.'; 
      }
  } else {
      $query5 = "INSERT INTO `order_item`(`order_item_id`, `product_id`, `quantity`,`order_id`) VALUES (NULL,'$product_id','$quantity','$order_id')";
      $result5 = mysqli_query($connection, $query5);
      if (!$result5) {
      die("Database query failed.");
      } else {
          echo 'The item has been added to your cart. &lt;a class="text-red" href="viewcart.php"&gt;View your cart&lt;/a&gt;&lt;/div&gt;.'; 
      }
  }
  
  // 4. Release returned data
  mysqli_free_result($result);
  
  // 5. Close database connection
  mysqli_close($connection);
  ?&gt;
  </code></pre>
  
  <p>The weird thing is that my website still seems to work. These lines of code are part of a shopping cart module and the shopping cart seems to get updated.</p>