mysqli_free_result

I am very new to php and I am trying to write a few simple php scripts just to get a feel for the language.

I am having a problem with one script that keeps on returning this warning message:
Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in /home/solare11/public_html/rk/test-connect.php on line 27

Source line 27 is:
mysqli_free_result($result01);

I am not attempting to write cutting edge code here, I just want to experiment with how certain things work. So, I am not interested in recoding this as PDO, nor security faults etc. I just want to know what is wrong with this code and how I should correct it.

I have read the php documentation and searched the web for answers to this and I have seen so many different answers that I am just totally confused ???

Can any friendly person out there give me a solution?

Thanks.

HERE IS MY SOURCE:

[php]// define database variables
$host = ‘localhost’;
$user = $_SERVER[‘DBUSER’];
$pass = $_SERVER[‘DBPASS’];
$db = $_SERVER[‘DBRK’];

$mysqli=mysqli_connect($host,$user,$pass,$db);
if(mysqli_connect_errno()) die('Connection Error ‘.mysqli_connect_errno().’ : '.mysqli_connect_error());
mysqli_set_charset($mysqli,‘utf8’);

echo “
We are here 01
”;

$query=“SELECT * FROM customer”;
if($result=mysqli_query($mysqli,$query)){
while($row=mysqli_fetch_assoc($result)){
echo "Customer id: " . $row[‘custid’] . " Password: " . $row[‘password’] . “
”;
}
mysqli_free_result($result);
}

echo “
We are here 02
”;

$query=“UPDATE customer SET password=‘aaabbb’ WHERE custid=‘71’”;
$result01=mysqli_query($mysqli,$query);
mysqli_free_result($result01);

echo “
Result02 is:
” . $result02;

?>[/php]

INSERT, UPDATE and DELETE queries return true or false so $result01 is not a mysqli result. No need to call mysqli_free_result() on it.

Absolutely brilliant, AbraCadaver, Simple language that even I can understand :wink:

Many thanks for taking the effort to sort that out for me - you wouldn’t beleve how long I spent looking for the answer !

Sponsor our Newsletter | Privacy Policy | Terms of Service