我正在尝试使用“echo”显示一些变量和表单,例如收件箱类型的消息。
问题是没有显示回声,也不知道如何修复它。
当我点击主题标题上的主题字段时,应显示“echo”但不显示。
贝娄是代码:
<?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>";
}
}
}
?>
Bellow是my_messages.php中的所有代码。我决定把它放在这里所有的代码,以避免任何有关丢失代码信息的问题。也许会有助于解决错误。
当我尝试点击我的收件箱时,问题出现在代码的末尾,当我点击发件人主题时,不显示邮件。表单未显示echo函数。
<?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 :(得分:0)
var_dump( $row_message)
从数据库中取出之后查看其中的内容。 请考虑更改此行
$row_message = mysqli_fetch_array($run_message);
到此
$row_message = mysqli_fetch_assoc($run_message);
mysqli_fetch_array不会返回关联数组,因为您希望在代码中进一步访问。
答案 1 :(得分:0)
请确保您在msg_id
等查询字符串中传递someurl?msg_id=1
,否则您将看不到任何内容
if(isset($_GET['msg_id'])){
/* get msg_id details from db and show */
}
这是因为我们在这里检查是否设置了msg_id
然后显示内容。 ;)