Page 1 of 1

problem with making rss with PHP

Posted: Sat Aug 25, 2012 6:42 am
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

Re: problem with making rss with PHP

Posted: Sat Aug 25, 2012 2:37 pm
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.

Re: problem with making rss with PHP

Posted: Sun Aug 26, 2012 12:10 am
by m2babaey
Yes, the problem was in the IF-ELSE
Thanks