0
I am doing a function that when it receives a number , in case, an id it makes a query and rescues the name that is in that id and I come across this error.
code
function catporid($cat){
global $aCon;
$sql = 'SELECT cat_nome FROM cat WHERE cat_id = $cat';
$query = $aCon->query($sql);
$r = $query->fetch_array();
$cat = $r['cat_nome'];
return $cat."id";
}
Apply correction to variable
$cat
using quotation marks, so what you get is a bool instead of the desired object.– Edilson
fixed only that the error still remains $sql = "SELECT cat_name FROM cat WHERE cat_id = '$cat'";
– Drbs
Look at the answer, I’ve presented two ways you can fix that.
– Edilson
Related, if not duplicated: https://answall.com/questions/28184/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in
– Inkeliz
@Edilson solved ! was a column with a different name and changed the code a little .. thanks !
– Drbs
Even if an answer has already been chosen, I would like to add an important tip. Whenever such an error occurs it is because there is a syntax error in the sql query. Instead of guessing where the error is, just use the connection variable to return the last error. Something like this: echo $conexao->error;
– Juven_v