Warning: mysqli_fetch_object() expects Parameter 1 to be mysqli_result, Boolean Given in /home/omeganim/public_html/index.php on line 39

Asked

Viewed 1,423 times

0

I am in need of help to resolve this error!!!

Warning: mysqli_fetch_object() expects Parameter 1 to be mysqli_result, Boolean Given in /home/omeganim/public_html/index.php on line 39

The code is this:

 $pagCorrente = 1;
 if(isset($_GET['pag'])){
     $pagCorrente = (int)$_GET['pag'];
 }
 $mostrar = 10;


 $pagCorrente = $pagCorrente * $mostrar - $mostrar;



 $sql = "SELECT count(id) as total FROM listas";     
 $ex = $conexao->query($sql);    
 $total = mysqli_fetch_object($ex);  
 $total = $total->total;

 $quantPages = ceil($total / $mostrar);




 $sql = "SELECT * FROM listas ORDER BY id desc LIMIT $pagCorrente,$mostrar";
 $wx = $conexao->query($sql);





 while($linha = mysqli_fetch_object($wx)){


 ?>
 <div class="engloba1">
  <div>


    <a href="<?php echo SITE . 'nomes.php?id='.$linha->id; ?>">
    <img src='<?php echo SITE . 'php/upload/' . $linha->imagen;?>' />

    <div class='box'>
     <p>
      <br><?php echo $linha->titulo;?> </br>
      </a>
      <a href="<?php echo SITE . 'nomes.php?id='.$linha->id; ?>">
      <br><?php echo $linha->nome;?> </br>
      <br><?php echo $linha->epi;?> </br>
      </a>
     </p>
     </div>
     </div>
   </div>

   <?php } ?>

Thank you in advance!!

  • welcome rafael, the error is on line 39 and you only posted 4 lines, publish your code so we can analyze the error.

1 answer

0


Usually this error happens when the query executed in the database shows some error.

Soon after the execution of $conexao->query print the last error that happened in the database with $conexao->error. Thus remaining:

 /* ... ... */
 $sql = "SELECT count(id) as total FROM listas";     
 $ex = $conexao->query($sql);   

 echo $conexao->error;

 $total = mysqli_fetch_object($ex);  
 $total = $total->total;

 $quantPages = ceil($total / $mostrar);

 $sql = "SELECT * FROM listas ORDER BY id desc LIMIT $pagCorrente,$mostrar";
 $wx = $conexao->query($sql);

 echo $conexao->error;
 exit; //opcional, para poder visualizar melhor a saida de erro
 while($linha = mysqli_fetch_object($wx)){

 /* ... ... */

There is an error in your sql query (it may be a misspelled column name, etc) not to guess.

I noticed an important detail. Your variable $conexao is an instance of the mysqli class? In other words, you made a $conexao = new mysqli(...)? The above method will only work if it is done that way. Also you can simply call fecth_object straight from the resultset. Something like this: $conexao->fetch_object();

  • No database Selected Warning: mysqli_fetch_object() expects Parameter 1 to be mysqli_result, Boolean Given in /home/omeganim/public_html/index.php on line 42

  • I assume you did not put the name of the bank when creating the connection variable. Something like: $conexao = new mysqli('host', 'usuario', 'senha', 'nome_do_banco');. Check this out.

  • i did so : $host= "197.47.180.159"; $banco= "bank"; $usuario= "root"; $password= "123"; $connected= mysqli_connect($host,$user, $password); $connected -> select_db($bank);

  • I made it so that you just said and gave another error:Warning: mysqli::mysqli(): (HY000/1044): Access denied for user 'omeganim_e'@'servidor.linknacional.com.br' to database 'omeganim_anime' in /home/omeganim/public_html/php/conexao.php on line

  • The user has omeganim_e and is not allowed to access the database omeganim_anime. It may be a password problem, but if you can access the administration web interface with these credentials that shouldn’t be it. Or it may be that in the database settings there are no write permissions, or the server in question cannot be accessed remotely (blocked outside the hosting, I suppose the mysql server in question is online). To solve just put your scripts inside your hosting that should work.

  • Vlw ae pcr managed to resolve was user error. Vlw by help

Show 1 more comment

Browser other questions tagged

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