So I am using php to create a xml document based on data in a MySql database. But for some reason when I view the xml.php doc on my website the browser doesn't recognize it should be read as an xml doc and I get this error:
Warning: Cannot modify header information - headers already sent by (output started at blah/xml.php:1) in blah/xml.php on line 3
I replaced the doc structure of my site with blah.
Here is the php code:
It's funny too because when I view the source code of the xml.php file it looks exactly like an xml doc with xml version and everything.PHP Code:<?php
header("Content-type: text/xml");
$dbName = "dbname";
$link = mysql_connect("mydb", "user", "pass") or die("Could not connect.");
$db = mysql_select_db($dbName, $link);
$query = "select * from item order by id ";
$result = mysql_query($query, $link) or die("Could not complete database query");
$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
$_xml .="<portfolio>\r\n";
for($x=0; $x<mysql_num_rows($result); $x++) {
$row = mysql_fetch_assoc($result);
$_xml .="\t<item link=\"" . $row["link"] . "\">\r\n";
$_xml .="\t<title>" . $row["title"] . "</title>\r\n";
$_xml .="\t<descrip>" . $row["description"] . "</descrip>\r\n";
$_xml .="\t\t<img>" . $row["img"] . "</img>\r\n";
$_xml .="\t</item>\r\n";
}
$_xml .="</portfolio>";
echo $_xml;
?>



Reply With Quote



Bookmarks