Jump to content

[SOLVED] unexpected T_STRING


Simsonite

Recommended Posts

Hi, Firstly i bet this error is so obvious, but i just cant see it.

 

Here is the error message

Parse error: syntax error, unexpected T_STRING in /home/dancdoit/public_html/news/test.php on line 9

 

Here is the code

<?php
include 'includes/config.php';
include 'includes/dbopen.php';
$query  = "SELECT * FROM tt_posts";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$content = "<ol>";
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$content = "<div id=\"news <?php echo $row['id'] ?>\">";
$content .= "<div id=\"newsheader\"><h2><?php echo $row['title'] ?></h2></div>";
$content .= "<div id=\"newscontent\"><p><?php echo $row['body'] ?></p>";
$content .= "<hr>";
$content .= "<p align=\"right\"><?php echo \"<a href='comment \" . $row['id'] . \".php'>Comments</a>\"; ?></p>";
$content .= "<div id=\"newsfooter\">";
$content .= "<p id=\"author\"><a href=\"/forums/memberlist.php?mode=viewprofile&u=<?php echo $row['uid'] ?>\"><?php echo $row['author'] ?></a></p>";
$content .= "<p id=\"date\"><?php echo $row['created'] ?></p>";
$content .= "</div>";
$content .= "</div>";
$content .= "<br />";
$content .= "<br />";
}
$content .= "</ol>";
include 'includes/dbclose.php';
?>

Link to comment
Share on other sites

here is the new code

 

<?php
include 'includes/config.php';
include 'includes/dbopen.php';
$query  = "SELECT * FROM tt_posts";
$result = mysql_query($query) or die('Error : ' . mysql_error());
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$content = "<ol>";
$content = "<div id=\"news {$row['id']}\">";
$content .= "<div id=\"newsheader\"><h2>{$row['title']}</h2></div>";
$content .= "<div id=\"newscontent\"><p>{$row['body']}</p>";
$content .= "<hr>";
$content .= "<p align=\"right\"><a href='comment/{$row['id']}.php'>Comments</a></p>";
$content .= "<div id=\"newsfooter\">";
$content .= "<p id=\"author\"><a href=\"/forums/memberlist.php?mode=viewprofile&u={$row['uid']}\">{$row['author']}</a></p>";
$content .= "<p id=\"date\">{$row['created']}</p>";
$content .= "</div>";
$content .= "</div>";
$content .= "<br />";
$content .= "<br />";
$content .= "</ol>";
}

echo $content;

include 'includes/dbclose.php';
?>

Link to comment
Share on other sites

And it still not outputting anything?

 

Looking at your code, this:

while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$content = "<ol>";
$content = "<div id=\"news {$row['id']}\">";
$content .= "<div id=\"newsheader\"><h2>{$row['title']}</h2></div>";
$content .= "<div id=\"newscontent\"><p>{$row['body']}</p>";

 

needs to be

$content = null;
while($row = mysql_fetch_assoc($result))
{
$content .= "<ol>";
$content .= "<div id=\"news {$row['id']}\">";
$content .= "<div id=\"newsheader\"><h2>{$row['title']}</h2></div>";
$content .= "<div id=\"newscontent\"><p>{$row['body']}</p>";

Link to comment
Share on other sites

It is coming up with the following error messages when i do error_reporting(E_ALL);

 

Notice: Undefined index: id in /home/dancdoit/public_html/news/test.php on line 17

 

Notice: Undefined index: title in /home/dancdoit/public_html/news/test.php on line 18

 

Notice: Undefined index: body in /home/dancdoit/public_html/news/test.php on line 19

 

Notice: Undefined index: id in /home/dancdoit/public_html/news/test.php on line 21

 

Notice: Undefined index: uid in /home/dancdoit/public_html/news/test.php on line 23

 

Notice: Undefined index: author in /home/dancdoit/public_html/news/test.php on line 23

 

Notice: Undefined index: created in /home/dancdoit/public_html/news/test.php on line 24

 

I have copied the script to connect to the database into the script but it still doesnt work.

The same script works for other pages

Link to comment
Share on other sites

Nope they were right i think something went wrong when i was connecting to the database because i inserted a different script to connect to the database and it worked

 

What is wrong with this script?

 

<?php

$database[dbserver]="localhost";
$database[dbuser]="*******";
$database[dbname]="*******";
$database[dbpass]="****";

$connect = mysql_connect($database['dbserver'], $database['dbuser'], $database['dbpass']);

$select= mysql_select_db($database['dbname']);
$query  = "SELECT * FROM tt_posts";
$result = mysql_query($query) or die('Error : ' . mysql_error());
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.