Error while making select

0
  

Warning: mysqli_fetch_assoc () expects parameter 1 to be mysqli_result, boolean given

I already tested fetch_array , fetch_object , I do not know how to do it.

    function pegaId($nomeConteudo){
    $query = "select id from conteudo where nomeConteudo = {$nomeConteudo} ";
    $resultado = mysqli_query($this->conexao, $query);
    $value = mysqli_fetch_assoc($resultado);
    return $value;
}

I just want to get the ID value, but it does not return me. How to do?

-

The proposed solution did not fit my problem, although it did not return any more errors in this new way:

    function pegaId($nomeConteudo){
    $query = "select id from conteudo where nomeConteudo = {$nomeConteudo} ";
    //$resultado = mysqli_query($this->conexao, $query);
    $resource = mysqli_query($this->conexao, $query);
    return $resource;
}

It does not return any value here:

$id = $conteudo_fkid->pegaId($nomeConteudo);
echo $id;

So I still need to do a select, and I'm not getting it. How to proceed?

    
asked by anonymous 02.09.2018 / 00:00

1 answer

0

Reason

The error in the query occurs because you are not passing the variable between quotes in query . And because it is a string , it is necessary.

Correcting

function pegaId($nomeConteudo){
    $query = "select id from conteudo where nomeConteudo = '{$nomeConteudo}'";
    //$resultado = mysqli_query($this->conexao, $query);
    $resource = mysqli_query($this->conexao, $query);
    return $resource;
}

Attention

It's very important to know how to find the problem. So a simple form that could be used in this case:

It would simply add% with% below the line that , see the output (which will be the query ready), copy and query directly on Bank.

So you'll be sure your query is correct, and you can continue analyzing the next few lines of your code.

    
02.09.2018 / 23:49