PDO::ERRMODE_EXCEPTION )); } catch (Exception $e) { die("Error : ".$e->getMessage()); } if (isset($_SESSION['username'])) { $req = $db->prepare('SELECT id FROM `authors` WHERE username=:username'); $req->execute(array( "username"=>$_SESSION['username'] )); if ($data = $req->fetch()) { $sender_id = $data['id']; } } else { $_SESSION['error_msg'] = "You must be logged in to receive an send message."; header('Location: /auth/login'); } if (isset($_GET['author'])) { if (!is_numeric($_GET['author'])) { $req = $db->prepare('SELECT id FROM `authors` WHERE username=:username'); $req->execute(array( "username"=>$_GET['author'] )); if ($data = $req->fetch()) { $user_id = $data['id']; } else { $user_id = $_GET['author']; } $req = $db->prepare('SELECT username FROM `authors` WHERE id=:id'); $req->execute(array( "id"=>$sender_id )); if ($data = $req->fetch()) { $addressee = $data['username']; } } $req = $db->prepare('SELECT * FROM `messages` WHERE message_by=:sender_id AND message_to=:user_id OR message_by=:sender_id AND message_to=:user_id ORDER BY message_datetime ASC'); $req->execute(array( "sender_id"=>$sender_id, "user_id"=>$user_id )); $result = $req->fetchAll(); } ?> Explore | Chiro - Canto

Discussion

prepare('UPDATE `messages` SET message_read=1 WHERE id=:id'); $req->execute(array( "id"=>$message_id )); if ($message['message_by'] == $_SESSION['username']) { $class = "right"; } else { $class = "left"; } ?>