5

Why am I getting this error message:

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given

My code is:

$statement = "INSERT INTO table1 (data1, data2) VALUES ('$variable1', '$variable2')";

if ($result = mysqli_query($conn,$statement)) {
echo "New record added successfully";
          } else {
    echo "Error adding records: " . $result . "<br>" . mysqli_error($conn);
}

echo "Adding records finished. ";

mysqli_free_result($result);
Dharman
  • 30,962
  • 25
  • 85
  • 135
Tass Mark
  • 337
  • 1
  • 2
  • 14

1 Answers1

8

As stated in the mysqli_query manual:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

Your insert query will return true or false, but not an object. So, calling mysqli_free_result will not work here.

Burki
  • 1,188
  • 19
  • 28