0

My scenario is first i was running it in localhost and the xml works fine. But when i uploaded it to domain. The page doesn't show the xml anymore, it only shows a blank page. But when i tried to inspect it, there is data in the xml but it was also a nested xml. Here's my code.

<?php
require("config.php");

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

// Opens a connection to a MySQL server
$connection=mysqli_connect($databaseHost, $databaseUsername, $databasePassword);
if (!$connection) {
  die('Not connected : ' . mysqli_error());
}

// Set the active MySQL database
$db_selected = mysqli_select_db($connection, $databaseName);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysqli_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysqli_query($connection, $query);
if (!$result) {
  die('Invalid query: ' . mysqli_error($connection));
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo "<?xml version='1.0' ?>";
echo '<markers>';
$ind=0;
// Iterate through the rows, printing XML nodes for each
while ($row = @mysqli_fetch_assoc($result)){
  // Add to XML document node
  echo '<marker ';
  echo 'id="' . $row['id'] . '" ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'contact_number="' . parseToXML($row['contact_number']) . '" ';
  echo 'contact_number1="' . parseToXML($row['contact_number1']) . '" ';
  echo 'contact_number2="' . parseToXML($row['contact_number2']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'image="' . $row['image'] . '" ';
  echo '/>';
  $ind = $ind + 1;
}

// End XML file
echo '</markers>';

?>

I used the same code running in my localhost and domain, but in the domain there's nothing.

SEE IMAGE enter image description here

WHEN I TRIED TO SEE THE DOM(ctrl + U), this is what it shows enter image description here

gwapo
  • 178
  • 2
  • 4
  • 28
  • 1
    nested? like how..? could you post what did you see? also, have checked the page source? – Bagus Tesa May 23 '18 at 03:18
  • I already added a picture – gwapo May 23 '18 at 03:34
  • Your page appears to still be HTML. View the actual source of the page (Ctrl+U) instead of using the DOM inspector. Is your code adding the `` and `` tags? – Phil May 23 '18 at 03:44
  • I already posted the DOM inspector, and no i dont put body and html tags. My code above is just that. What I am curious is that in localhost it works fine but that it was uploaded in server it has that output where it is just blank – gwapo May 23 '18 at 03:57
  • 1
    Why don't you use SimpleXML to create xml? http://php.net/manual/en/book.simplexml.php – Justinas May 28 '18 at 07:01
  • Your page source looks correct. Does the _Network_ console show the content-type as `text/xml` or `text/html`? – Phil May 28 '18 at 07:01
  • Also, looks like you have a blank line at the start of the output. Could be coming from your PHP above or from `config.php`. In any case, it's probably preventing your `Content-type` header from being set. You should enable error reporting and display, ie `ini_set('display_errors', 'On'); error_reporting(E_ALL);`. I bet you get the _"headers already sent"_ warning – Phil May 28 '18 at 07:03
  • Possible duplicate of [How to fix “Headers already sent” error in PHP](https://stackoverflow.com/q/8028957/283366) – Phil May 28 '18 at 07:07

1 Answers1

0

I figured out that the php version of my domain and the local isn't the same. I changed the php version in my domain and it works already!

gwapo
  • 178
  • 2
  • 4
  • 28