这是我的“阅读消息”代码......
我想添加一个代码来了解消息是否已被读取...
<?php
session_start();
$userfinal=$_SESSION['sessioname'];
require "config.php";
$messageid = $_GET['messageid'];
$message = mysql_query("SELECT * FROM messages WHERE message_id = '$messageid' AND to_user = '$userfinal'");
$message=mysql_fetch_assoc($message);
echo "<h1>Title: ".$message['message_title']."</h1><br><br>";
echo "<h3>From: ".$message['from_user']."<br><br></h3>";
echo "<h3>Message: <br>".$message['message_contents']."<br></h3>";
echo '<form name="backfrm" method="post" action="inbox.php">';
echo '<input type="submit" value="Back to Inbox">';
echo '</form>';
?>
答案 0 :(得分:0)
如果用户访问此页面,他们已阅读此电子邮件。因此,只需在此代码中添加消息tabele的更新:
<?php
session_start();
$userfinal=$_SESSION['sessioname'];
require "config.php";
$messageid = $_GET['messageid'];
$message = mysql_query("SELECT * FROM messages WHERE message_id = '$messageid' AND to_user = '$userfinal'");
$message=mysql_fetch_assoc($message);
// set message as read
$result = mysql_query("UPDATE messages SET `has_been_read` = 1 WHERE message_id = '$messageid'");
if ( !$result ) {
// error updating the message to has_been_read
// This bit is up to you!!!
}
echo "<h1>Title: ".$message['message_title']."</h1><br><br>";
echo "<h3>From: ".$message['from_user']."<br><br></h3>";
echo "<h3>Message: <br>".$message['message_contents']."<br></h3>";
echo '<form name="backfrm" method="post" action="inbox.php">';
echo '<input type="submit" value="Back to Inbox">';
echo '</form>';
?>