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

混江龙づ霸主 提交于 2020-03-23 06:19:06

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/31557639/warning-mysqli-free-result-expects-parameter-1-to-be-mysqli-result-boolean-g

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