Error while doing select

Asked

Viewed 54 times

0

Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given

I already tested the fetch_array, fetch_object, I don’t 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 receive the ID value, but it does not return to me. How to do?

--

The proposed solution did not suit my problem, although it did not return more errors making 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 returns no value to me here:

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

So I’m still needing to make a select, and I’m not getting it. How to proceed?

  • André, welcome. The question that has been marked, it contains the answer to your problem. Do the [tour] to find out how the site works, if you need help with the site’s tools, go to [help].

  • You haven’t solved my problem, Noobsaibot

  • I think I made a mistake, see: https://answall.com/questions/68124/

  • I still meet with difficulty.

1 answer

0


Motive

Error in query occurs because it is not passing the variable between quotation marks in query. And for being 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;
}

Heed

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

Simply, it would add echo $query; below the line mounting the query, see the output (which will be the query ready), copy and make the direct query in the bank.

So you’ll make sure your query is correct, and you can continue analyzing the next lines of your code.

  • Thank you very much, solved the problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.