2016-03-18 79 views
-2

我想显示一些变量和形式像收件箱类型的消息与“回声”。“回声”未显示在php

问题是回显不显示,不知道如何修复它。

当我点击主题标题上的主题字段应显示“回声”,但它没有。

贝娄是代码:

<?php 

if(isset($_GET['msg_id'])){ 

    $get_id = $_GET['msg_id']; 

    $sel_message = "select * from messages where msg_id='$get_id'"; 

    $run_message = mysqli_query($con, $sel_message); 

    $row_message = mysqli_fetch_array($run_message); 

    $msg_subject = $row_message['msg_sub']; 
    $msg_topic = $row_message['msg_topic']; 
    $reply_content = $row_message['reply']; 

    //updating the unread message to read 
    $update_unread = "update messages set status='read' where msg_id='$get_id'"; 
    $run_unread = mysqli_query($con, $update_unread); 


    echo " 
     <center><br /> 
      <hr> 
      <h2>$msg_subject</h2><br/> 

      <p><b>Message:</b>$msg_topic</p><br /> 

      <p><b>My reply:</b>$reply_content</p><br/> 

      <form action='' method='post'> 
       <textarea cols='60' rows='10' name='reply'></textarea><br /><br /> 
       <input type='submit' name='msg_reply' value='Reply to this' /> 
      </form> 
     </center> 
    "; 
} 

if(isset($_POST['msg_reply'])){ 
    $user_reply = $_POST['reply']; 

    if($reply_content!='no_reply'){ 
     echo "<h2 align='center'>This message was already replied!</h2>"; 
     exit(); 
    } else { 
     $update_msg = "update messages set reply='$user_reply' where msg_id='$get_id'"; 

     $run_update = mysqli_query($con, $update_msg); 

     echo "<h2 align='center'>Message was replied!</h2>"; 
    } 
} 

} 

?> 

贝娄是从my_messages.php的所有代码。我决定把它放在这里所有的代码,以避免任何有关缺少代码信息的问题。也许会有助于获得错误。

问题出在代码结束时,当我点击我的收件箱,并且当我点击发件人主题时邮件没有显示。该窗体不显示回显功能。

<?php 

session_start(); 
include("includes/connection.php"); 
include("functions/functions.php"); 

if(!isset($_SESSION['user_email'])){ 

    header("location: index.php"); 
} 
else{ 
?> 
<!DOCTYPE HTML> 



<html> 


    <head> 

     <title>Welcome User!</title> 
     <link rel="stylesheet" type="text/css" href="styles/home_style.css" media="all"> 

    </head> 


    <body> 

     <!-- Container starts --> 
     <div class="container"> 

      <!-- Header Wrapper Starts --> 

      <div id="head_wrap"> 

       <!-- Header Starts --> 
       <div id="header"> 

        <ul id="menu"> 
         <li><a href="home.php">Home</a></li> 
         <li><a href="members.php">Memebers</a></li> 
         <strong>Topics:</strong> 
         <?php 

         $get_topics = "select * from topics"; 
         $run_topics = mysqli_query($con, $get_topics); 

         while($row= mysqli_fetch_array($run_topics)){ 

          $topic_id = $row['topic_id']; 
          $topic_title = $row['topic_title']; 

          echo "<li><a href='topic.php?topic=$topic_id'>$topic_title</a></li>"; 

         } 



         ?> 
        </ul> 

        <form method="get" action="results.php" id="form1"> 
         <input type="text" name="user_query" placeholder="Search a topic"/> 
         <input type="submit" name="search" value="Search"/> 
        </form> 

       </div> 
       <!-- Header Ends --> 

      </div> 
      <!-- Header Wrapper Ends --> 

      <!-- Content area starts --> 
      <div class="content"> 

       <!-- User timeline starts --> 
       <div id="user_timeline"> 

        <div id="user_details"> 
         <?php 
         $user = $_SESSION['user_email']; 
         $get_user = "select * from users where user_email='$user'"; 
         $run_user = mysqli_query($con, $get_user); 
         $row = mysqli_fetch_array($run_user); 

         $user_id = $row['user_id']; 
         $user_name = $row['user_name']; 
         $user_country = $row['user_country']; 
         $user_image = $row['user_image']; 
         $register_date = $row['register_date']; 
         $last_login = $row['last_login'];  


         $user_posts = "select * from posts where user_id='$user_id'"; 
         $run_posts = mysqli_query($con, $user_posts); 
         $posts = mysqli_num_rows($run_posts); 

         //getting the number of unread messages 

         $sel_msg = "select * from messages where receiver='$user_id' AND status='unread' order by 1 DESC"; 

        $run_msg = mysqli_query($con, $sel_msg); 

        $count_msg = mysqli_num_rows($run_msg); 

         echo " 
          <center><img src='user/user_images/$user_image' width='240' height='240'/></center> 
           <div id='user_mention'> 
          <p><strong>Name:<strong> $user_name</p> 
          <p><strong>Country:<strong> $user_country</p> 
          <p><strong>Last Login:<strong> $last_login</p> 
          <p><strong>Member Since:<strong> $register_date</p> 

          <p><a href='my_messages.php?inbox&u_id=$user_id'>Messages ($count_msg)</a></p> 
          <p><a href='my_posts.php?u_id=$user_id'>My Posts ($posts)</a></p> 
          <p><a href='edit_profile.php?u_id=$user_id'>Edit My Account</a></p> 
          <p><a href='logout.php'>Logout</a></p> 
          </div> 
          "; 

         ?> 
        </div> 

       </div> 
       <!-- User timeline ends --> 

       <!-- Content timeline starts --> 
       <div id="msg" align="center"> 

        <p align="center"> 
         <a href="my_messages.php?inbox">My Inbox</a> || 
         <a href="my_messages.php?sent">Sent Items</a> 
        </p> 

        <?php 
        if(isset($_GET['sent'])){ 
         include("sent.php"); 
        } 
        ?> 

        <?php if(isset($_GET['inbox'])){ ?> 


        <table width="800" align="center"> 



         <tr> 

          <th>Sender:</th> 
          <th>Subject</th> 
          <th>Date</th> 
          <th>Reply</th> 

         </tr> 


         <?php 

        $sel_msg = "select * from messages where receiver='$user_id' order by 1 DESC"; 

        $run_msg = mysqli_query($con, $sel_msg); 

        $count_msg = mysqli_num_rows($run_msg); 

        while($row_msg= mysqli_fetch_array($run_msg)){ 


         $msg_id = $row_msg['msg_id']; 
         $msg_receiver = $row_msg['receiver']; 
         $msg_sender = $row_msg['sender']; 
         $msg_sub = $row_msg['msg_sub']; 
         $msg_topic = $row_msg['msg_topic']; 
         $msg_id = $row_msg['msg_id']; 
         $msg_date = $row_msg['msg_date']; 


        $get_sender = "select * from users where user_id='$msg_sender'"; 
        $run_sender = mysqli_query($con, $get_sender); 
        $row = mysqli_fetch_array($run_sender); 

        $sender_name = $row['user_name']; 

        ?> 


         <tr align="center"> 

          <td> 
           <a href="user_profile.php?u_id=<?php echo $msg_sender; ?>" target="_blank"> 
           <?php echo $sender_name; ?> 
           </a>  
          </td> 
          <td><a href="my_messages.php?msg_id=<?php echo $msg_id; ?>"><?php echo $msg_sub; ?></a></td> 
          <td><?php echo $msg_date; ?></td> 
          <td><a href="my_messages.php?msg_id=<?php echo $msg_id; ?>">Reply</a></td> 

         </tr> 

        <?php } ?> 

        </table> 

        <?php 

        if(isset($_GET['msg_id'])){ 

         $get_id = $_GET['msg_id']; 

         $sel_message = "select * from messages where msg_id='$get_id'"; 

         $run_message = mysqli_query($con, $sel_message); 

         $row_message = mysqli_fetch_array($run_message); 

         $msg_subject = $row_message['msg_sub']; 
         $msg_topic = $row_message['msg_topic']; 
         $reply_content = $row_message['reply']; 

         //updating the unread message to read 
         $update_unread = "update messages set status='read' where msg_id='$get_id'"; 
         $run_unread = mysqli_query($con, $update_unread); 


         echo "<center><br/><hr> 
          <h2>$msg_subject</h2><br/> 

          <p><b>Message:</b>$msg_topic</p><br/> 

          <p><b>My reply:</b>$reply_content</p> 

          <br/> 
           <form action='' method='post'> 
            <textarea cols='60' rows='10' name='reply'></textarea><br/><br/> 
            <input type='submit' name='msg_reply' value='Reply to this'/> 
           </form> 
           </center> 

          "; 

        } 

        if(isset($_POST['msg_reply'])){ 
         $user_reply = $_POST['reply']; 

         if($reply_content!='no_reply'){ 
          echo "<h2 align='center'>This message was already replied!</h2>"; 
          exit(); 

         } 

         else{ 

         $update_msg = "update messages set reply='$user_reply' where msg_id='$get_id'"; 

         $run_update = mysqli_query($con, $update_msg); 



          echo "<h2 align='center'>Message was replied!</h2>"; 

         } 
        } 

        } 
        ?> 

       </div> 
      </div> 
      <!-- Content area ends --> 

     </div> 
     <!-- Container ends -->  

    </body> 

</html> 
<?php } ?> 
+0

你是说你的回声没有显示任何东西? – Erick

+0

是的!什么也没有 –

+0

我认为这只是你的代码的一部分?因为否则它是非常合乎逻辑的,它不会起作用。 – icecub

回答

0
var_dump($row_message) 

从数据库中获取,看看有什么在它之后。 请考虑改变这一行

$row_message = mysqli_fetch_array($run_message); 

对此

$row_message = mysqli_fetch_assoc($run_message); 

mysqli_fetch_array如要进一步访问你的代码不会返回关联数组。

+0

我试过...它的行为相同 –

0

请确保您传递msg_id查询字符串如someurl?msg_id=1,否则你将看不到里面

if(isset($_GET['msg_id'])){ 
    /* get msg_id details from db and show */ 
} 

这是因为这里如果msg_id设置然后显示的内容我们正在检查什么。 ;)

+0

msg_id在查询字符串“​​ “>” –