homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

RSS Feed valid but not working

 3:06 pm on Aug 15, 2008 (gmt 0)

Hi I just tried my firt PHP RSS feed. I built the code like I would an HTML file from a PHP script.

The DB query works, I tested it in phpMyAdmin, the feed validates at feedvalidator.org but the page remains empty.

I wonder what's wrong with my code:

<?xml version="1.0"?>
<?php header("Content-type: text/xml"); ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

<atom:link href="http://www.MYSITE.com/result_news.xml" rel="self" type="application/rss+xml" />

<title>MYSITE.com News</title>
<description>News from my community</description>

$filename = "inc/#*$!X.php";
if (file_exists($filename)) include("inc/#*$!X.php");

$query_news = "
SELECT id, news_title, party_group ,city, state, country
FROM news
WHERE date_start <= CURDATE() AND date_end >= CURDATE()
AND live = '1'
ORDER BY date_created DESC
LIMIT 0,15
$result_news = mysql_query($query_news)
or die ("Couldn't execute the News query.");

while ($row_news = mysql_fetch_array($result_news))
$h_news_title = html_entity_decode($news_title, ENT_QUOTES, "UTF-8");
$h_party_group = html_entity_decode($party_group, ENT_QUOTES, "UTF-8");
$h_city = html_entity_decode($city, ENT_QUOTES, "UTF-8");
$h_country = html_entity_decode($country, ENT_QUOTES, "UTF-8");
echo "<item>\n";
echo "<title>".$h_news_title."</title>\n";
echo "<description>".$h_news_title."</description>\n";
echo "<link>http://www.MYSITE.com/pl.php?p=news_item.php&amp;id=".$id."&amp;section=news</link>\n";
echo "</item>\n";




 5:17 pm on Aug 15, 2008 (gmt 0)

Hi, I feel like a fool! I forgot my db connection script so there was no db connection. Now after a few adjustments, it is working.


 5:18 pm on Aug 15, 2008 (gmt 0)

Is the page completely blank or is it not displaying the RSS feed as it should?

The major thing I see missing is the header. Place this at the top of the document before anything is echoed. It will tell the browsers the file is an RSS feed.

header('Content-type: application/rss+xml; charset=UTF-8');


 5:19 pm on Aug 15, 2008 (gmt 0)

Nevermind. :)


 6:05 pm on Aug 15, 2008 (gmt 0)

Thanks anyway for replying!


 10:22 pm on Aug 15, 2008 (gmt 0)

header data must be sent before any other data is sent to the browser.

instead of
<?xml version="1.0"?>
<?php header("Content-type: text/xml"); ?>

you should have

<?php header("Content-type: text/xml"); ?>
<?xml version="1.0"?>

sending headers after data has already been sent to the browser should throw an error or warning.


 10:52 pm on Aug 15, 2008 (gmt 0)

Thank you, I changed the order of the two first lines.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved