Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to all this and would love to be able to get this to work.

I am trying to create this RSS feed using PHP and Mysql.

I am recieving the following error though:

"Parse error: syntax error, unexpected T_STRING" - in line 16 which is <?xml.....

<?php

//setting the variables
$host = '';
$database = '';
$username = '';
$password = '';

//connecting to the database and server
$db_handle = mysql_connect($host, $username, $password);
$db_found = mysql_select_db($database, $db_handle);

header('Content-Type: application/xml; charset=ISO-8859-1');

?>
<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0">

<channel>
    <title>'.$row['title'].'</title>
    <about>'.$row['about'].'</about>
    <logo>'.$row['logo'].'</logo>
    <website>'.$row['website'].'</website>
    <phone>'.$row['phone'].'</phone>
    <email>'.$row['email'].'</email>
    <facebook>'.$row['facebook'].'</facebook>
<?php
$query = mysql_query("SELECT title, link, description FROM posts");

while($row = mysql_fetch_array($query)){
echo '<item>
    <title>'.$row['title'].'</title>
    <about>'.$row['about'].'</about>
    <logo>'.$row['logo'].'</logo>
    <website>'.$row['website'].'</website>
    <phone>'.$row['phone'].'</phone>
    <email>'.$row['email'].'</email>
    <facebook>'.$row['facebook'].'</facebook>
  </item>';
}
echo '
</channel></rss>';
?>

i have tried looking but can't see the error.

share|improve this question
 
possible duplicate of PHP error in .xml file? –  hakre 5 hours ago

2 Answers

You have short tags enabled so the <? in <?xml is causing PHP to interpret it as an opening PHP tag.

To solve this just echo out that line:

echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
share|improve this answer

Your web server is recognizing <? as an opening php tag with the <?xml causing an issue.

Use <?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; ?>

Instead of <?xml version="1.0" encoding="ISO-8859-1"?>

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.