nathanmaxsonadil Posted August 14, 2007 Share Posted August 14, 2007 I'm trying to create a dynamic rss feed but now when I got to the feed it gives me this error. XML Parsing Error: junk after document element Location: http://www.myblog.com/feednews/ Line Number 2, Column 1:<b>Warning</b>: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in <b>/myhome_dir/feednews/index.php</b> on line <b>19</b><br /> ^ <?php //Tell the browser that we're XML header("Content-type: text/xml"); //Lets connect to MySQL $host = 'localhost'; $username = 'my_user'; $password = 'my_pass'; $db_name = 'my_db'; @mysql_connect($host, $username, $password); @mysql_select_db($db_name); $query = @mysql_query("SELECT title, author, content, date, id FROM `your_posts` ORDER BY `id` DESC LIMIT 10"); //Begin the RSS $rss = "<rss version=\"2.0\"> <channel> <title>My Blog!</title> <description>My blog</description> <link>http://www.myblog.com/blog</link>"; //Form each one of our items while($r = mysql_fetch_assoc($query)) { $rss .= "<item> <title>{$r['title']}</title> <author>{$r['author']}</author> <pubDate>{$r['date']}</pubDate> <description>{$r['content']}</description> <link>http://www.myblog.com/view.php?id={$r['id']}</link> </item>"; } //Close up our channel and RSS $rss .= "</channel> </rss>"; //Output the RSS and die die ($rss); ?> What's the matter with my code above? Quote Link to comment https://forums.phpfreaks.com/topic/64951-solved-xml-parsing-error-junk-after-document-ele/ Share on other sites More sharing options...
hvle Posted August 14, 2007 Share Posted August 14, 2007 my best bet is that xml parser stuck at the question mark symbol. try replace the question mark with "?" All character in rss have to be encoded with html special characters Quote Link to comment https://forums.phpfreaks.com/topic/64951-solved-xml-parsing-error-junk-after-document-ele/#findComment-324108 Share on other sites More sharing options...
rlindauer Posted August 14, 2007 Share Posted August 14, 2007 Looks like the query is failing. You are suppressing errors, so it might be a good idea to add some error detection while still in production: <?php $query = @mysql_query("SELECT title, author, content, date, id FROM `your_posts` ORDER BY `id` DESC LIMIT 10") or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64951-solved-xml-parsing-error-junk-after-document-ele/#findComment-324109 Share on other sites More sharing options...
nathanmaxsonadil Posted August 14, 2007 Author Share Posted August 14, 2007 I took of my @'s and it says it can not connect but it takes off 2 characters of my username! Quote Link to comment https://forums.phpfreaks.com/topic/64951-solved-xml-parsing-error-junk-after-document-ele/#findComment-324117 Share on other sites More sharing options...
nathanmaxsonadil Posted August 14, 2007 Author Share Posted August 14, 2007 Ok i got it to work now I had put `your_posts` instead of `news` and I changed my mysql query from mysql_connect("localhost", "username", "pass"); mysql_select_db("db"); to mysql_connect ("localhost", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("db"); Quote Link to comment https://forums.phpfreaks.com/topic/64951-solved-xml-parsing-error-junk-after-document-ele/#findComment-324122 Share on other sites More sharing options...
rlindauer Posted August 14, 2007 Share Posted August 14, 2007 It is usually a good idea to not suppress errors when still in production. The errors are there to help you. Quote Link to comment https://forums.phpfreaks.com/topic/64951-solved-xml-parsing-error-junk-after-document-ele/#findComment-324123 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.