Jump to content

rss feeds


sudsy1970

Recommended Posts

Hi i have a simple blog which is stored in a table called messages, i have tried to create an rss feed that poeple can link to but am a bit stuck.  the feed does not validate with the error code of:

 

 

Sorry This feed does not validate.

 

  line 15, column 2: XML parsing error: <unknown>:15:2: not well-formed (invalid token) [help]

 

       

    $sql = "SELECT title FROM messages ORDER BY date_added DESC limit 0,10";

 

 

Anybody got any ideas on this please, have read the rss pages and can comsume a fedd ok just cant produce one.

 

<?php

$host     = "";
$user     = "";
$pass     = "";
$port     = "3306";
$database = "uni";

$MySQL = mysql_connect( "$host:$port", $user, $pass );

mysql_select_db( $database, $MySQL) or die ( "Couldn't open $database: ".mysql_error() );

?>
  
  // Get latest items from db
  $sql = "SELECT title FROM messages ORDER BY date_added DESC limit 0,10";
  $rst = mysql_query($sql);
  
  // Loop through data and build feed items
  $items = "";
  while($a_row = mysql_fetch_assoc($rst))
  {
    $items.= "<item>";
    $items.= "  <title>{$rst['title']}</title>";
    $items.= "  <link>{$rst['link']}</link>";
    $items.= "  <description>{$rst['description']}</description>";
    $items.= "</item>"; 
  }
  
  // Build feed text
  $feed = "<?xml version=\"1.0\"?>";
  $feed.= "<rss version=\"2.0\">";
  $feed.= "  <channel>";
  $feed.= "    <title>My cool feed</title>";
  $feed.= "    <link>http://mi-linux.wlv.ac.uk/~0274148/AWT/blog/index.php</link>";
  $feed.= "    <description>A cool feed</description>";
  $feed.= "    $items";
  $feed.= "  </channel>";
  $feed.= "</rss>";
  
  // Display feed text
  echo $feed;

Link to comment
https://forums.phpfreaks.com/topic/219386-rss-feeds/
Share on other sites

sorry should have said, I have already tried that and still get the same error message.

 

When i posted the the code i hadn't realised i had moved the <? tag when fiddling.

 

have also been playing with my link tag when i think should read :

 

$feed.="<link>localhost/bloggy/index.php</link>";

 

does this look right for the file on a web server ?

Link to comment
https://forums.phpfreaks.com/topic/219386-rss-feeds/#findComment-1138301
Share on other sites

ok have struggled on a bit more and now i have the error message

  Quote
XML Parsing Error: XML declaration not well-formed

Location: http://127.0.0.1/bloggy/feed.xmlLine Number 3, Column 19: $host    = "http://mi-linux.wlv.ac.uk/~0274148";

-----------------^

 

This is pointing to the colon, i have tried adding a " afterwards as i thought it may view it as a special charaacter but end up with the same error.

 

Can one explain it to me please ?

 

Link to comment
https://forums.phpfreaks.com/topic/219386-rss-feeds/#findComment-1139074
Share on other sites

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.