problem with making rss with PHP

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
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

problem with making rss with PHP

Post by m2babaey »

Hi
I have problem with rss feed I have made with PHP
Firefox is understanding my code and displayes the feed, but rss validators and IE8 are not working with it
Here is my code:

Code: Select all

<?php
 require("dbconnect.php"); 
// 
else
{
	$website_URLq=MYSQL_FETCH_ARRAY(mysql_query("SELECT * FROM settings WHERE set_name='website_URL' "));
	$website_URL=$website_URLq['set_value'];

header("Content-Type: application/rss+xml; charset=ISO-8859-1"); 
echo ('<?xml version="1.0" encoding="ISO-8859-1" ?>');

?>

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

<channel>
  <title>website title RSS FEED</title>
  <link>http://mywebsite.net</link>
  <description>The newest changes to customers and orders.</description> 
<atom:link href="<?php echo $website_URL;?>/rss_feed.php" rel="self" type="application/rss+xml" />
<?php

$result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 ");
while($row=mysql_fetch_array($result)){

//some php code here

$item="<item>
<guid isPermaLink='false'>$guide</guid>
    <title>$title</title>
    <link>$link</link>
    <description>$desc</description>
  </item>";

echo $item;
}
}
?>
</channel>
</rss>
When I use validators, it seems the last 2 lines:
</channel>
</rss>
are the first things they see and return parse error
Could anyone help me solve this problem?
Thanks in advance
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: problem with making rss with PHP

Post by requinix »

Code: Select all

 tags don't work right - use [syntax=php].

That lone "else" you have at the top... what is it doing there? You put the <rss> and <channel> inside it but the closing </channel> and </rss> are outside, so if the if earlier was true (and the else doesn't execute) there'll be those two hanging out at the end.
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Re: problem with making rss with PHP

Post by m2babaey »

Yes, the problem was in the IF-ELSE
Thanks
Post Reply