Jump to content

Problems with making a php forum


VTS

Recommended Posts

I have most of the program done for making a forum with php. The problem that I am running into is with a program that shows the posts in a topic. When I click on a topic, it displays a blank page. Any help would be greatly appreciated.

here is the code from the prog that shows the posts in a topic:

<?php

/**
* A script that shows the posts in a topic
*
* @version $Id$
* @copyright 2006
*/
// check for required info from the query string
if (!isset($_GET['topic_id'])) {
header("Location: topiclist.php");
exit;
}
// connect to server and select database
$conn = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("testDB", $conn) or die(mysql_error());

// verify that the topic exists
$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>You have selected an invalid topic. Please
<a href=\"topiclist.php\">try again</a>.</em></p>";
} else {

// get topic title
$topic_title = stripslashes(mysql_result($verify_topic_res, 0, 'topic_title'));

// gather the posts
$get_posts = "select post_id, topic_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());

$sql = "SELECT topic_id, post_text
FROM forum_posts
WHERE topic_id = $_GET[topic_id]";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($array = mysql_fetch_array($result)) {
echo "Text for the topic: " . $array['post_text'] . "<br />";
}

// create the display string
$display_block = "
<p>Showing posts for the <strong>$topic_title</strong> topic:</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 = n12br(stripslashes($posts_info['post_text']));
$post_create_time = $posts_info['fmt_post_create_time'];
$post_owner = stripslashes($posts_info['post_owner']);

// add to display
$display_block .= "
<tr>
<td width=35% valign=top>$post_owner<br>$fmt_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>";
} // while
// close up the table
$display_block .= "</table>";
} //end else

?>
<html>
<head>
<title>Posts in Topic</title>
</head>
<body>
<h1>Posts in Topic</h1>
<?php print $display_block;
?>
<p><a href="topiclist.php">Click Here</a> to go back to the main topic page</p>
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/8668-problems-with-making-a-php-forum/
Share on other sites

Hey VTS,


It seems we have the same book. Good advise from Meloni isn't it? :)

Now, one thing I had to do to get this code running was to change the:


if (!isset($_GET['topic_id'])) {
header("Location: topiclist.php");
exit;
}



//for:



if(!$topic_id){
header("Location: topic_list.php");
exit;


}



You see, the $_GET[] global array was not working, so I just used straight the $topic_id passed to this file from topiclist.php.


If you entered already posts to the forum, you should be able to get them from the database.

If it worked on mine, it should work on yours... ;)


Well, let me know if you need more help





Alberto

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.