Possible Duplicate:
Headers already sent by PHP
I am attempting to follow this tutorial:
Creating a Store Locator with PHP, MySQL & Google Maps
Google Geo APIs Team; August 2009
I've reached the point where I have a MySQL table of location data. I changed elements of the code in this tutorial for my purposes. I simply would like to extract all the data from the MySQL table and convert it into XML, so it can be read by the Google Maps API.
Unfortunately, when I run the code below, the browser page does not load and receive the following error:
Warning: Cannot modify header information - headers already sent by (output started at .../getdata/genxml.php:8) in .../getdata/genxml.php on line 43
This may be the problematic line:
header("Content-type: text/xml");
Here is the entire block of code. What mistake am I making? Thanks!
<?php
require("phpsqlsearch_dbinfo.php");
//Get parameters from URL
//$center_lat = $_GET["lat"];
//$center_lng = $_GET["lng"];
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}
// Search the rows in the markers table
$query = sprintf("SELECT * FROM markers WHERE 1");
$result = mysql_query($query);
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// **Below is line 42. The error may be here.**
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("id", $row['id']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("bt", $row['bt']);
$newnode->setAttribute("dt", $row['dt']);
$newnode->setAttribute("br", $row['br']);
$newnode->setAttribute("bth", $row['bth']);
$newnode->setAttribute("sqft", $row['sqft']);
$newnode->setAttribute("lp", $row['lp']);
$newnode->setAttribute("url", $row['url']);
$newnode->setAttribute("dom", $row['dom']);
}
echo $dom->saveXML();
?>