title: MySQL to XML message header issue
body: <p>I have a problem with generating xml from MySQL which appears to be related to the message header <strong>header("Content-type: text/xml");</strong>  <a href="https://stackoverflow.com/questions/11083084/alternative-to-headercontent-type-text-xml">This link</a> refers to this issue but does not solve the problem in my case. The post refers to the 2007 GMap example, not  <a href="https://developers.google.com/maps/articles/phpsqlsearch_v3#creating-the-map" rel="nofollow noreferrer">the updated 2009 version</a></p>
  
  <p>Here is the code in full...</p>
  
  <pre><code>$center_lat = $_GET["lat"];
  $center_lng = $_GET["lng"];
  $radius = $_GET["radius"];
  // Start XML file, create parent node
  $dom = new DOMDocument("1.0");
  $node = $dom-&gt;createElement("markers");
  $parnode = $dom-&gt;appendChild($node);
  
  // Opens a connection to a mySQL server
  $connection=mysql_connect ("99.99.99", "abcdefg", "zzzzzz");
  if (!$connection) {
    die("Not connected : " . mysql_error());
  }
  
  // Set the active mySQL database
  $db_selected = mysql_select_db("xxxxxxx", $connection);
  if (!$db_selected) {
    die ("Can\'t use db : " . mysql_error());
  }
  
  // Search the rows in the markers table
  $query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers ",
    mysql_real_escape_string($center_lat),
    mysql_real_escape_string($center_lng),
    mysql_real_escape_string($center_lat),
    mysql_real_escape_string($radius));
  $result = mysql_query($query);
  
  if (!$result) {
    die("Invalid query: " . mysql_error());
  } 
  // - !!!! This is the problem line !!!!!
  //header("Content-type: text/xml");
  
  // Iterate through the rows, adding XML nodes for each
  $i = 1;
  while ($row = mysql_fetch_assoc($result)){
    echo $i.$row['name']."&lt;br&gt;";  // names correctly displayed
    $node = $dom-&gt;createElement("marker");
    $newnode = $parnode-&gt;appendChild($node);
    $newnode-&gt;setAttribute("name", $row['name']);
    $newnode-&gt;setAttribute("address", $row['address']);
    $newnode-&gt;setAttribute("lat", $row['lat']);
    $newnode-&gt;setAttribute("lng", $row['lng']);
    $newnode-&gt;setAttribute("distance", $row['distance']);
    $i = $i + 1;
  }
  
  echo $dom-&gt;saveXML();
  echo "done ".$i;  // Script ends ok $i = 16
  </code></pre>
  
  <p>Everything appears to be working as shown by the echo statements - however, due to the absence of the message header line, no xml is echoed to the screen.</p>
  
  <p>What am I doing wrong ?</p>