View Full Version : XML Mysql Php
SChaput
07-09-2009, 08:19 PM
I am trying to create a feed of my website, using my mysql database. I have found many tutorials on these but i cant seem to get any of them working, i keep getting the same error.
Safari can’t open the page.
Safari can’t open the page “feed://mypage.net/feed.xml”. The error is: “The feed could not be loaded because the content is not in a known feed format.” (PubSub:2) Please choose Safari > Report Bugs to Apple, note the error number, and describe what you did before you saw this message.
I am trying to use the tutorial found here.
http://www.webwicked.com.au/downloads/PHP_MySQL_RSSFeed.pdf
any help is appreciated, thanks.
Jesdisciple
07-10-2009, 03:42 AM
Can you link to the running application? A copy of the (censored) PHP source would be good as well.
I'm particularly interested in looking at your XML output, as that seems to be where the problem lies.
SChaput
07-10-2009, 07:52 PM
Here is the code
<?php
header(“Content-type: text/xml”);
echo “<?xml version=\”1.0\” encoding=\”UTF-8\”?>”;
// Set RSS version.
echo “
<rss version=\”2.0\”> “;
// Start the XML.
echo “
<channel>
<title>Feed title</title>
<description>A description of the feed contents</description>
<link>http://www.yoursite.com/</link>”;
mysql_connect("","","");
mysql_select_db("");
// Query database and select the last 10 entries.
$data = mysql_query(“SELECT * FROM hmr ORDER BY id DESC LIMIT 10”);
while($row = mysql_fetch_array($data))
{
// Continue with the 10 items to be included in the <item> section of the XML.
echo “
<item>
<link>http://www.yoursite.com/article.php?id=”.$row[id].”</link>
<guid isPermaLink=\”true\”>http://www.yoursite.com/article.php?id=”.$row[id].”</guid>
<title>Title Here</title>
<description><![CDATA[“.$row[entrytext].”]]></description>
<comments>http://www.yoursite.com/article.1
</item>”;
}
// substr can limit the number of characters. First number is starting point while the second number is number of
characters.
// otherwise just use $row[Intro].
// <guid> is an optional sub-element of <item> but recommended if you don’t want to receive a warning when
validating your RSS.
echo “
</channel>
</rss>”;
?>
And it can be found here..
feed://roomwatch.uuuq.com/feed.xml
Jesdisciple
07-10-2009, 08:07 PM
Your server isn't recognizing your PHP as needing to be parsed, so the browser is receiving the PHP instead of its output. EDIT: I discovered this by viewing the file's source, just like with an HTML page.
There are two ways to make it work. If you want to parse PHP in all .xml files within a certain directory, you can configure this on your server; Apache uses the AddHandler directive (http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addhandler) for this.
If you want to make this work on a per-file basis instead (or you can't/don't want to mess with the server's configuration), just rename the file with a .php extension (feed.php or feed.xml.php). Your content-type header will inform the browser about what the output is.
I read somewhere that some browsers will choke on the space after the colon, but I can't find anything to cite for that.
SChaput
07-11-2009, 12:09 AM
Still no luck
seen here : feed://roomwatch.uuuq.com/feed.xml.php
i also tried changing the extension to just .php, same error.
I'm actually using bluehost as a webhost this is just my test area.
Does anyone know if bluehost has some special way to do what im attempting too?
Thanks
Jesdisciple
07-11-2009, 12:55 AM
Nope, this is a different error - maybe not when Safari interprets it as XML, though. Try visiting the actual feed.
Parse error: syntax error, unexpected ':' in /www/uuuq.com/r/o/o/roomwatch/htdocs/feed.xml.php on line 2
Line 2 in your previously posted source is:
header(“Content-type: text/xml”);I don't see where the error is coming from, unless... Try exchanging those quotes for copies of this one: "
SChaput
07-11-2009, 02:24 AM
Haha tried changing the " around. Still no luck with anything in particular. I figured this would be simpler then it is turning out to be. Are there any options available to me?
Jesdisciple
07-11-2009, 05:00 AM
What are you editing in? I know those quotes look different, and that's the only way a syntax error could be found inside a string, especially that early in the code...
EDIT: I just verified this as the problem by running your code on my localhost.
SChaput
07-11-2009, 12:19 PM
You used the exact code i posted above and it worked fine? Very strange. I did notice as you stated earlier, the " were an odd sort of ". After changing that i still had no luck.
When you got it to work did you save as a .php or .xml
SChaput
07-11-2009, 01:01 PM
Finally got it figured it out.
feed://ihatemyroommate.net/feed.php
I used a different tutorial, seemed even more basic and used your advice on the .php extension. I was under the impression an RSS feed needed to be .xml
Thanks alot for your help!
Jesdisciple
07-11-2009, 03:21 PM
I think changing the quotes didn't help because you were using Microsoft Word or some other desktop publisher to edit your code. I took the first two lines of your source and replaced the quotes. I ended up with this source (named xml.php) which gave the correct error (below):
<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
?>
XML Parsing Error: no element found
Location: http://localhost/lib/PHP/xml.php
Line Number 1, Column 39:
<?xml version="1.0" encoding="UTF-8"?>
--------------------------------------^
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.