Php mysqli_fetch_arrays fails after sql join query

i have 2tables: pub/prop. columns : pub: idpub/cont/stt/cbl/dtp prop: idprop/nomett/npprop/adrprop/cnprop/psdprop/mdpprop

this is the query and php code:

   //including the database connection file
    include_once("config.php");
    $idprop= $_SESSION['psdprop'];
     $result = mysqli_query($mysqli, "SELECT * FROM pub
    INNER JOIN prop ON pub.cbl = prop.nomett ");```

fetching->

<table width='80%' border=0>
    <tr bgcolor='#CCCCCC'>
    <td>Cont</td>
    </tr>
  ```  <?php 

    while($res = mysqli_fetch_array($result)) {     
    echo "<tr>";
    echo "<td>".$res['cont']."</td>"; 
    }
     ?>
    </table>

when i execute the code below no result is displayed inside the table and the msg error is the following: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in /opt/lampp/htdocs/SYC/cprop/coprop-dashboard.php on line 92.

when i execute the query in phpmyadmin its successful but return no row even if there is content in the tables.

Your query is failing.

mysqli_query will return false if the query fails; this means $result is being set to false. That’s the boolean being referenced in your error.

You can see what error is being given by using mysqli_error:

var_dump(mysqli_error($mysqli));

after your call to mysqli_query.

As an aside, you should look at using PDO to interact with your database. It’s a little different to mysqli, but it makes it easier to write secure code.

Sponsor our Newsletter | Privacy Policy | Terms of Service