This code tests to see if there was a result before freeing it up:
$result = mysql_query($query) or die("$query\n\n" . mysql_error());
$id = mysql_insert_id();
if ($result) { mysql_free_result($result); }
But it gives this warning:
mysql_free_result() expects parameter 1 to be resource, boolean given in /foo/bar/etc.php
What am I doing wrong?
Since you have called
mysql_insert_id(), I assume you performed anINSERTquery rather than aSELECT. In that case (as with others where no rowset is returned),$resultis merely a boolean TRUE on success, not a result resource. There’s no need to free it, and indeed trying to free it results in a warning.From the documentation on
mysql_query():However, that doesn’t mean you shouldn’t error-check it.