问题
I'm running into many problems with a code I've been working on, but this one seems to come up a lot. I'm using the procedural method for coding this site, and I can't seem to find an answer to this question without the mention of OOP's, prepared statements or failed queries. The funny thing is the statement works from the website, and the string still gets added to the database so I don't think its a failed query. Can anyone help me understand what this warning statement means?
Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in .....on line (pick a number)
This is one of the codes I'm working with.
if (isset($_POST['picturesubmit']))
{
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['profilepic']['name']);
$ext = $_FILES['profilepic']['type'];
if(($ext == "image/jpeg") || ($ext == "image/jpg") || ($ext == "image/png") || ($ext == "image/gif"))
{
$temp_file = $_FILES['profilepic']['tmp_name'];
if(move_uploaded_file($temp_file, $target_path))
{
$picture = mysqli_real_escape_string($dbc, $target_path);
$q = "UPDATE Users SET profilepic = '$picture' WHERE email = '$sessionuser' ";
$r = mysqli_query ($dbc, $q)
or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
mysqli_free_result($r);
}
else
{
echo "Picture did not upload properly. please try again";
}
}
else
{
echo "Uploaded file was not an image, please try again.";
}
}
回答1:
mysqli_free_result
is not necessary for write statment as mysqi_query
return boolean (true),
it does not return a result identifier resource,
so you can not free the result
refer to the docs :- http://php.net/manual/en/mysqli.query.php
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.
来源:https://stackoverflow.com/questions/8454310/mysqli-free-result-warning-explaination