Jump to content


How do I create an RSS feed with PHP?

  • Please log in to reply
1 reply to this topic

#1 netfrugal

  • Members
  • PipPip
  • Member
  • 26 posts

Posted 25 September 2006 - 10:38 PM

I need help here.  I see so many xml rss feeds out there and wonder how they dynamically populate their feeds.

Below is the code I am using from a tutorial I found online. But I still get validation errors that I simply do not understand. I've tested the feed on 3 different readers: Mozilla thunderbird, RssReader 1.0, and FeedReader 2.90.

The tutorial showed me to create the feed with a .php extension.  Are not RSS feeds in XML? 

You can test the feed at marcsteele.com/z.php in a rss reader.
FeedValidator.org gives me the following errors:

The weird thing is that I can get it to work on my localhost db, but not when I upload it to my server and call data from the production server's db.

I am using IIS for the production server, and apache for my localhost. I can't image why that would make a difference.

The only other issue I can image that is affecting the output is maybe apostrophes or special characters. Any help would be appreciated.

My code:

header("Content-Type: text/xml;charset=utf-8");
$connection = @mysql_connect("localhost", "root", "password");
$db = @mysql_select_db('pl', $connection);
$sql = "SELECT * from products_description";
$result = @mysql_query($sql, $connection);
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<title>Testing Oscommerce RSS Feeds</title>
<description>Testing out Dynamic RSS feed from mysql.</description>
while($row = mysql_fetch_array($result)) {
$name = $row['products_name'];
// display an item

#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 September 2006 - 11:31 PM

Have you tried correcting the errors generated?

You have formatting in your XML, I don't think that's correct, I think you have to have a seperate stylesheet for formatting.

Try making changes as suggested by feed validator.

1. Remove the
2. Get rid of the
3. Make sure the SQL actually works first by using something like phpMyAdmin.

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users