vendredi 3 septembre 2021

Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in [duplicate]

Heres the full error message

Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\VMEG\index2.php:57 Stack trace: #0 C:\xampp\htdocs\VMEG\index2.php(57): mysqli_num_rows(false) #1 {main} thrown in C:\xampp\htdocs\VMEG\index2.php on line 57.

Heres my codes

<td>
<?php
$sql = "SELECT username FROM highscore ORDER BY score DESC LIMIT 10;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
   
if($resultCheck > 0){
      while($row = mysqli_fetch_assoc($result)) {
         echo $row['username']. "<br>" ;
      }
}
?>                       
</td>   
<td>
<?php
$sql = "SELECT score FROM highscore ORDER BY score DESC LIMIT 10;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
   
if($resultCheck > 0){
  while($row = mysqli_fetch_assoc($result)) {
     echo $row['score']. "<br>" ;
  }
}
?>                       
</td>

this happens because I created this codes in my laptop and it works but when I tried opening this in my friends desktop this error message appear

btw this is how my database looks like

userid | username | score
  1    |    123   |   10
  2    |    321   |   23

Aucun commentaire:

Enregistrer un commentaire