I'm getting 'Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\xampp\htdocs\forum\showtopic.php on line 38' error on the php code from a tutorial I'm trying, and I cant find where the problem is. I'm wondering if anyone here can find it, please.
I get the error when running the first lot of code, but not sure if the error could be on the second lot of code, which is being referenced. I think its probably the second lot [showtopic.php]
Any advice would be helpful...thanks.
topiclist.php:
Code: Select all
<?php
//connest to server and select database
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("forum", $conn) or die(mysql_error());
//gather the topics
$get_topics = "select topic_id, topic_title, date_format(topic_create_time, '%b %e %y at %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) {
//there are no topics, so say so
$display_block = '<p><em>No Topics exist,</em></p>';
} else {
//create the display topics
$display_block = "
<table cellpadding=3 cellspacing=1 border=1>
<tr>
<th>Topic Title</th>
<th>Number of posts</th>
</tr>";
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']);
//get number of posts
$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)');
//add to display
$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>";
}
//close up the table
$display_block .= "</table>";
}
?>
<html>
<head>
<title>Topics in the Forum</title>
<body>
<h1>Topics in the Forum</h1>
<?php print $display_block; ?>
<p>Would you like to <a href="addTopicForm.html"> add a Topic</a>?</p>
</body>
</head>
</html>
showtopic.php:
Code: Select all
<?php
//check for required info from the query string
if (!$_Get[topic_id]) {
header("Location: topiclist.php");
}
//connect to server and select database
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("forum", $conn) or die(mysql_error());
//verify 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) {
//this topic does not exist
$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, 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());
//create the display string
$display_block = "
<p>Showing posts for the <strong>$topic_title</strong> topic:</p>
<table width100% cellpadding=3 cellspacing=1 borderr=1>
<tr>
<th>AUTHOR</th>
<th>POST</th>
</th>;
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_posts_create_time'];
$post_owner = stringslashes($posts_info['post_owner']);
//add to display
$display-block .= "
<tr>
<td width35% valign=top>$post_owner<br>[$post_create_time]</td>
<td width65% valign =top>$post_text<br><br><a href=\"replytopost.php?post+id=$post_id\"><strong>REPLY TO POST</strong></a></td>
</tr>;
}
//close table
$disply_block .= "</table>"
}
?>
<html>
<head>
</title>Posts in Topic</title>
</head>
<body>
<h1>Posts in Topic</h1>
<?php print $display_block; ?>
</body>
</html>