Jump to content

Dynamic RSS Feed not working..


ajcarr1989

Recommended Posts

Hi,

I have a problem with an RSS Feed. the error im getting on the W3C validator is this:

This feed does not validate.

 

    *

 

      line 1, column 0: XML parsing error: <unknown>:1:0: syntax error [help]

 

          Query couldn't be executed

 

In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation.

 

    *

 

      "text/xml" media type is not specific enough [help]

 

 

 

.htaccess

AddType application/x-httpd-php .xml

 

rss.php

<?


//Set XML header for browser
header('Content-type: text/xml');

//Create the heading/channel info for RSS Feed
$output = '<rss version=\"2.0\">';
$output .= '<channel>';
$output .= '<title>Muzo Feed</title>';
$output .= '<description>Your RSS Feed Description</description>';
$output .= '<link>http://mi-linux.wlv.ac.uk/~0703272</link>';

//Individual Items of our RSS Feed
//Connect to a database and and display each new item in our feed    

//Connect to DB
$host = "localhost";          //Name of host
$user = "0703272";            //User name for Database
$pass = "rachel123";             //Password for Database
$db = "db0703272";          //Name of Database
mysql_connect($host,$user,$pass);

//Create SQL Query for our RSS feed
$sql = "SELECT `title`, `webaddress`, `message`, `date_added` FROM `messages`ORDER BY `date_added` DESC LIMIT 0 , 15";
$result = mysql_query($sql) or die ("Query couldn't be executed");  

//Create Loop for the individual elements in the RSS item section
while ($row = mysql_fetch_array($result))
{
$output .= '<item>';
$output .= '<title>'.$row['title'].'</title>';
$output .= '<link>http:/mi-linux.wlv.ac.uk/~0703272/blog.php'.$row['link'].'</link>';
$output .= '<message>'.$row['message'].'</description>';
$output .= '<date_added>'.$row['date'].'</pubDate>';
$output .= '</item>';
}

//Close RSS channel
$output .= '</channel>';
$output .= '</rss>';

//Display output in browser
echo $output;
?>

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/219849-dynamic-rss-feed-not-working/
Share on other sites

Right there in the script, I see "header('Content-type: text/xml');"...that's what the 2nd 'error' is telling you.  You're explicitly setting the header to be "text/xml" instead of "application/rss+xml" which is the MIME type made specifically for RSS.

 

Now as to the first error, you're missing the 1st xml element...<?xml version="1.0"?>

 

Also, posting exactly what your script produces will help greatly.

 

** On another note, it's usually a good idea to remove or obfuscate your database username and password.

*** The line AddType application/x-httpd-php .xml simply tells your server how to handle .xml files (currently it's being passed to PHP)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.