我目前正在为一个项目创建一个论坛,但我已经碰壁了,我完全不知道该怎么做。回复功能是我遇到的问题,我不知道如何在主题上显示回复,唯一的想法是从"主题"获取ID主题。数据库并将其插入"回复"数据库,是否有可能,如果是的话,我可能需要一些帮助。
<?php
session_start();
require('../connect2database/connection.php');
if ($_SESSION['username']!= NULL) {
?>
<strong>Welcome back <?php echo $_SESSION['username']; ?>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<center><strong><a href="../homepage/">Home Page</a></strong> | <strong>
<a href="/discussionforum/members/members.php">Members</a></strong> |
<strong><a href="/discussionforum/login/logout.php">Logout</a></strong>
</center>
<br/>
<center><?php
if ($_SESSION['userLevel']== '1'){
?>[<a href="reply.php"><button style="width: 150px";>Add Reply</button>
</a>]
<?
}
if ($_SESSION['userLevel']== '2'){
?>[<a href="reply.php"><button style="width: 150px";>Add Reply</button>
</a>]
<?
}
if ($_SESSION['userLevel']== '3'){
?>[<a href="reply.php"><button style="width: 150px";>Add Reply</button>
</a>]
<?
}
?></center>
<br />
<center>
<?php
if($_GET["tid"]){
$check = mysqli_query($db, "SELECT * FROM caseDiscTopics WHERE
topic_id='".$_GET['tid']."'") or die(mysqli_errno());
if(mysqli_num_rows($check)){
while ($row = mysqli_fetch_assoc($check)){
echo "<h1>".$row['topic_name']."</h1>";
echo "<h4>By: ".$row['topic_creator']."<br />Date:
".$row['topic_date']."</h4>";
echo "<br/>".$row['topic_content'];
}
}else{
echo "not found";
}
}else{
header ("<center>Location:
..discussionforum/homepage/index.php</center>");
}
?></center>
..<br />
..<br />
<center><p><h3>All Replies</h3></p></center><p>
<center>
<?php
if($_GET["rid"]){
$check1 = mysqli_query($db, "SELECT * FROM caseDiscReply WHERE
reply_id='".$_GET['rid']."'") or die(mysqli_error());
if(mysqli_num_rows($check1)){
while ($row1 = mysqli_fetch_assoc($check1)){
echo "<h4>By: ".$row1['reply_creator']."<br />Date:
".$row1['reply_date']."</h4>";
echo "<br/>".$row1['reply_content'];
}
}else{
echo "reply not found";
}
}else{
header ("<center>Location: ..discussionforum/homepage/index.php</center>");
}
?></center>
</body>
</html>
<?php
}else{
echo "You must be logged in.";
}
?>
上面的代码是我用来访问主题及其内容的代码,它完全正常,但是当我尝试访问回复内容时,你可以看到&#34; if($ _ GET [&#34;摆脱&#34;]){&#34;它没有显示回复内容。
我确信我做错了但我不知道是什么。非常感谢帮助。
此处还有我的主页的代码,可以点击和访问这些主题。
<?php
session_start();
require('../connect2database/connection.php');
if ($_SESSION['username']!= NULL) {
?>
<strong>Welcome back <?php echo $_SESSION['username']; ?>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<center><strong><a href="../homepage/">Home Page</a></strong> | <strong>
<a href="/discussionforum/members/members.php">Members</a></strong> |
<strong><a href="/discussionforum/login/logout.php">Logout</a></strong>
</center>
<br/>
<center><?php
if ($_SESSION['userLevel']== '1'){
?>[<a href="/discussionforum/post/post.php"><button style="width:
150px";>Post Topic</button></a>]
<?
}
?></center>
<br />
<center>
<?php echo '<table border="1px;">';?>
<tr>
<td>
<span>ID</span>
</td>
<td width="400px;" style="text-align: center;">
Name
</td>
<td width="150px;" style="text-align: center;">
Creator
</td>
<td width="100px;" style="text-align: center;">
Date
</td>
</tr>
</center>
</body>
</html>
<?php
$check = mysqli_query($db, "SELECT * FROM caseDiscTopics");
if(mysqli_num_rows($check) !=0){
while($row = mysqli_fetch_assoc($check)){
$tid = $row['topic_id'];
echo "<tr>";
echo "<td>".$row['topic_id']."</td>";
echo "<td style='text-align: center;'><a href='topic.php?
tid=$tid&rid=$rid'>".$row['topic_name']."</a></td>";
echo "<td style='text-align: center;'>".$row['topic_creator']."
</td>";
echo "<td style='text-align: center;'>".$row['topic_date']."</td>";
}
}else{
echo "There are no topics available.";
}
echo "</table>";
if(@$_GET['action'] == "logout"){
session_destroy();
header("Location: login.php");
}
}else{
echo "You must be logged in.";
}
?>