I cannot select a database using PHP

Asked

Viewed 45 times

0

Hi guys I’m not getting a select in my PHP database. I have tried to implement several solutions, but it always returns 0 Results, and I have data in my BD.

I am using external files to connect to the bank and they are working.

And the contents of spans are always empty.

<?php $idUser = $_SESSION["user_id"];

  if (mysqli_num_rows($result) > 0) {
         $result =  mysqli_query("SELECT idMessage, name, telefone, mensagem FROM Messages where Messages.idUser =  '$idUser' ");
          while($row = mysql_fetch_array($result)) :
            $id  = $row["idMessage"];
            $name = $row["name"];
            $mensagem = $row["mensagem"];
          endwhile;
       } else {
            echo "0 results";
          }
  ?>

      <span><?php  echo $id ?></span>
      <span><?php  echo $name ?></span>
      <span><?php  echo $mensagem ?></span>

1 answer

1


the $result I believe it must be before the if and not after. staying like this:

$result =  mysqli_query("SELECT idMessage, name, telefone, mensagem FROM Messages where Messages.idUser =  '$idUser' ");
if (mysqli_num_rows($result) > 0) {
         ...
         ...

Browser other questions tagged

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