I'm trying to send some data from my database depending on the sender's id and the id of the receiver but this one throws me an error.
Fatal error: Call to a member function fetch () on boolean in line 16
EDITED
<?php
require 'functions.php';
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "empleos";
$conexion = new PDO('mysql:host=localhost;dbname='.$db_name, $user, $pass);
$query = 'SELECT * FROM mensajes WHERE receiver = $us AND emitter = ? ORDER BY id DESC';
$run = $conexion->query($query);
while ($row = $run->fetch(PDO::FETCH_ASSOC)) :
?>
<!-- -->
<div id="chat_data">
<span style="color:green"><?php echo $row['nombre']; ?> </span><br>
<span style="color:brown"><?php echo $row['message']; ?></span>
<span style="float:right"><?php echo fecha($row['send']); ?></span><br><hr>
</div>
<?php endwhile; ?>
the $ us variable comes from a file called functions.php
@$us = $_SESSION['usuario'][0];
previously worked perfectly but I put the conditionals in the query WHERE receiver = $us AND emitter = emitter
and it was there when he started to throw that error
in my database I have it in the following way