消息交换应用程序

时间:2014-05-30 09:46:17

标签: php mysql sql email

我正在尝试与数据库建立消息交换应用程序。现在我有两个表:login_users和'email'来存储消息。 'email'的字段是id,from_user,to_user,subject,message,date和read(boolean)。 收件箱页面工作正常,它正确显示消息,但我的SENT页面没有。来自,消息和日期正确显示,但当我点击查看消息时,它会显示来自收件箱的消息。我有两个页面用于'收件箱'和'已发送'和一个单独的页面'读'​​以显示消息,所以我认为问题可能存在。你们可以检查一下这段代码,看看你能否发现错误?

<?php

    $user = $_SESSION['username'];
    $connect = mysql_connect("localhost", "root", "") or  die  (mysql_error());
    mysql_select_db("login") or die(mysql_error());

$view_msg = mysql_query("
SELECT * FROM email where to_user = '$user'");

$row = mysql_num_rows($view_msg);

if ($row !=0){

    echo "<table><tr>";
    while($rows = mysql_fetch_assoc($view_msg)){
        $id = $rows['id'];
        $to_user = $rows['to_user'];

        echo "<td>";
        echo "From:";
        echo "</td>";
        echo "<td>" ;
        echo "".$from = $rows['from_user']."";

        echo "</td>";
        echo "</tr>";

        echo "<tr>";
        echo"<td> </td>";
        echo "</tr>";

        echo "<tr>";
        echo "<td>";
        echo"Subject:";
        echo "</td>";
        echo "<td>" ;
        echo "".$subject = $rows['subject']."";
        echo "</td>";
        echo "</tr>";

        echo "<tr>";
        echo"<td> </td>";
        echo "</tr>";
            echo "<tr>";
        echo "<td>";
        echo "Message: ";
        echo "<td>";
        echo "<td>" ;
        echo "".$message = $rows['message']."";
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo"<td> </td>";
        echo "</tr>";
    }
    echo "<tr>";
    echo "<td colspan='2'> <a href='messages.php?id=compose&mid=$id&subject=RE:$subject&to=$from'>Reply  </a></td>";

    echo "</tr>";
    echo "</table>";


    if($to_user == $user) {

        $up = mysql_query ("
        UPDATE email SET read = '1' WHERE  id ='$id'

        ");
    }
    }
else{

    echo "You can't see the conversation!";
}

?>

0 个答案:

没有答案