Parse error: parse error, expecting `T_STRING' or `T_VARIABL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jeggae
Forum Newbie
Posts: 10
Joined: Fri Oct 10, 2008 4:53 am

Parse error: parse error, expecting `T_STRING' or `T_VARIABL

Post by Jeggae »

Hi
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>
Pulni4kiya
Forum Commoner
Posts: 35
Joined: Tue Apr 14, 2009 6:20 am

Re: Parse error: parse error, expecting `T_STRING' or `T_VARIABL

Post by Pulni4kiya »

I think the error is on line 35 of showtopic.php. You have to close the double quotes.

Btw php variables are case-sensitive. On line 3 of that file you have $_Get which must be $_GET.
Jeggae
Forum Newbie
Posts: 10
Joined: Fri Oct 10, 2008 4:53 am

Re: Parse error: parse error, expecting `T_STRING' or `T_VARIABL

Post by Jeggae »

Thanks Pulni4kiya, you were right :wink: Got me going again and I was able to clean it up and get rid of all the errors.
Most of them were probably silly basic errors.

It seems to be running right but the problem is the table in showtopic.php does not seem to be showing up, except the header, the header seems okay. I've pasted the table as an html document and the table was perfect, but as part of the php, does not seem to be running except the header.
Any ideas why please?

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 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']); 
 
        //add to display
        $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>";
    }
 
    //close table
    $display_block .= "</table>";
}
?>
 
<html>
<head>
<title>Posts in Topic</title>
</head>
<body>
<h1>Posts in Topic</h1>
<?php print $display_block; ?>
</body>
</html>

Table that doesn't show up except the header:

Code: Select all

<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 = nl2br(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>[$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>";
    }
 
    //close table
    $display_block .= "</table>";
Pulni4kiya
Forum Commoner
Posts: 35
Joined: Tue Apr 14, 2009 6:20 am

Re: Parse error: parse error, expecting `T_STRING' or `T_VARIABL

Post by Pulni4kiya »

Are you sure that the query returns any results?
Jeggae
Forum Newbie
Posts: 10
Joined: Fri Oct 10, 2008 4:53 am

Re: Parse error: parse error, expecting `T_STRING' or `T_VARIABL

Post by Jeggae »

Pulni4kiya wrote:Are you sure that the query returns any results?
Can you elaborate please?
Post Reply