2016-03-18 78 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在查詢字符串「​​ 「>」 –