Forum hjælp mig venligst
Jeg har skrevet et forum, men jeg kan ikke få reply til at virke. Ganske vist åbnes formularen til at reply'e, men reply'en bliver ikke sat ind i det topic som den skulle. Her er mine koder:Topiclist.php
================================
<?php
$conn = mysql_connect("", "", "")
or die(mysql_error());
mysql_select_db("viola",$conn) or die(mysql_error());
$get_topics = "select topic_id, topic_title, date_format(topic_create_time, '%b %e %Y %r') as fmt_topic_create_time,
topic_owner from forum_topics order by topic_create_time desc";
$get_topics_res = mysql_query($get_topics,$conn) or die(mysql_error());
if (mysql_num_rows ($get_topics_res) < 1) {
$display_block = "<P><em>Der er ingen topics.</em></p>";
}else{
$display_block = "
<table cellpadding=3 cellspacing=1 border=1>
<tr>
<th>Topic titel</th>
<th># of posts</th>
</tr>";
//20
while ($topic_info =
mysql_fetch_array($get_topics_res)) {
$topic_id = $topic_info['topic_id'];
$topic_title =
stripslashes($topic_info['topic_title']);
$topic_create_time =
$topic_info['fmt_topic_create_time'];
$topic_owner =
stripslashes($topic_info['topic_owner']);
//30
$get_num_posts = "select count(post_id) from forum_posts where topic_id = '$topic_id'";
$get_num_posts_res =
mysql_query($get_num_posts,$conn)
or die(mysql_error());
$num_posts = mysql_result($get_num_posts_res,0, 'count(post_id)');
$display_block .= "
<tr>
<td><a href=\"showtopic.php?topic_id=$topic_id\">
<strong>$topic_title</strong></a><br>
Created on $topic_create_time by $topic_owner</td>
<td align=center>$num_posts</td>
</tr>";
}
$display_block .= "</table>";
}
?>
<html>
<head> <title>Topics i forum</title>
</head>
<body>
<h1>Topics</h1>
<?php print $display_block; ?>
Vil du gerne <a href="AddTopic.htm">lol</a>?
</body></html>
=====
replytopost.php
====
<?php
$conn = mysql_connect("", "", "")
or die(mysql_error());
mysql_select_db("viola",$conn) or die(mysql_error());
if ($_POST[op] != "addpost") {
if (!$_GET[post_id]) {
header("Location: wievtopics.php");
exit;
}
//12
$verify = "select ft.topic_id, ft.topic_title from forum_posts as fp left join forum_topics as ft on
fp.topic_id = ft.topic_id where fp.post_id = $_GET[post_id]";
$verify_res = mysql_query($verify, $conn)
or die(mysql_error());
if (mysql_num_rows($verify_res) < 1) {
header("Location: topiclist.php");
exit;
} else {
$topic_id = mysql_result($verify_res,0,'topic_id');
$topic_title =
stripslashes(mysql_result($verify_res,0,'topic_title'));
//25
print "
<html><head><title>$topic_title</title>
</head>
<body>
<h1>Skriv en besked i $topic_title</h1>
<form method=post action=\"$_SERVER[PHP_SELF]\">
<p><strong>Din E-mail:</strong><br>
<input type=\"text\" name=\"post_owner\" size=40 maxlength=150>
<P><strong>Skriv tekst:</strong><br>
<textarea name=\"post\" rows=8 cols=40
wrap=virtual></textarea>
<input type=\"hidden\" name=\"op\"
value=\"addpost\">
<input type=\"hidden\" name=\"topic_id\"
value=\"$topic_id\">
<P><input type=\"submit\" name=\"submit\"
vale=\"Add Post\"></p>
</form>
</body>
</html>";
}
} else if ($_POST[op] == "addpost") {
if ((!$_POST[topic_id]) || (!$_POST[post_text]) ||
(!$_POST[post_owner])) {
header("Location: topiclist.php");
exit;
}
$add_post = "insert into forum_posts values
('', '$_POST[topic_id]', '$_POST[post_text]',
now(), '$_POST[post_owner]')";
mysq_query($add_post,$conn) or die(mysql_error());
header("Location: showtopic.php?topic_id=$topic_id");
exit;
}
?>
====
showtopic.php
====
<?php
if (!$_GET[topic_id]) {
header("Location: topiclist.php");
exit;
}
$conn = mysql_connect("", "", "")
or die(mysql_error());
mysql_select_db("viola",$conn) or die(mysql_error());
//11
$verify_topic = "select topic_title from forum_topics where topic_id = $_GET[topic_id]";
$verify_topic_res = mysql_query($verify_topic, $conn)
or die(mysql_error());
if (mysql_num_rows($verify_topic_res) < 1) {
$display_block = "<P><em>Dette indslag eksisterer ikke. Please <a href=\"topiclist.php\">try again.</a></em></p>";
}else{
$topic_title =
stripslashes(mysql_result($verify_topic_res,0,'topic_title'));
//21
$get_posts = "select post_id, post_text,
date_format(post_create_time, '%b %e %Y at %r')
as fmt_post_create_time, post_owner from forum_posts where topic_id = $_GET[topic_id]
order by post_create_time asc";
$get_posts_res = mysql_query($get_posts,$conn)
or die(mysql_error());
//29
$display_block = "
<P>Viser posts for <strong>$topic_title</strong></p>
<table width=100% cellpadding=3 cellspacing=1 border=1>
<tr>
<th>AUTHOR</th>
<th>POST</th>
</tr>";
while ($posts_info =
mysql_fetch_array($get_posts_res)) {
$post_id = $posts_info['post_id'];
$post_text =
nl2br(stripslashes($posts_info['post_text']));
$post_create_time =
$posts_info['fmt_post_create_time'];
$post_owner =
stripslashes($posts_info['post_owner']);
//48
$display_block .="
<tr>
<td width=35% valign=top>$post_owner<br>
[$post_create_time]</td>
<td width=65% valign=top>$post_text<br><br>
<a href=\"replytopost.php?post_id=$post_id\">
<strong>REPLY TO POST</strong></a></td>
</tr>";
}
$display_block .="</table>";
}
?>
<html>
<head>
<title>Posts in Topic</title>
</head>
<body>
<h1>Posts in Topic</h1>
<?php print $display_block; ?>
</body>
</html>
