PHP error when displaying search result with select

Asked

Viewed 326 times

0

Error while selecting database data.

$rs = $conexao->query("SELECT FROM cadastro WHERE ID_Cliente = '83'");

$row = $rs->fetch_assoc();
echo $row['nome'];

Fatal error: Uncaught Error: Call to a Member Function fetch_assoc() on Boolean in

  • @Inkeliz has nothing duplicated. Only one entry in the BD.

  • 2

    It’s exactly the same question. Your query is wrong, the SELECT is empty, soon returns false and you want to do false->fetch_assoc()... Change to SELECT *, for example. It’s exactly @rray’s answer "When you come across the above error, it means that your query failed to know the source of the error". If that’s not duplicated...

  • @Inkeliz True. puts, forgot this silly detail... kkkk

1 answer

0

Regarding your question about mysql and mysqli. First it is important to know which shape mysql works in procedural and mysqli of the object-oriented form. Here you find how to work both ways.

The mistake happens because your query is bringing false.

Fatal error: Uncaught Error: Call to a Member Function fetch_assoc() on Boolean in

The correct is to do a validation

$sql = "SELECT * FROM `usuario` LIMIT 5";
$query = mysqli_query($con, $sql);

if ($query) {
    // Pode fazer assim
    while ($usuario = mysqli_fetch_object($query)) {
        // Exibe um link com a notícia
        echo $usuario->nome . ' - ' . $usuario->email;
        echo '<br/>';
    }
} 

Browser other questions tagged

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