0

When I use the below code and parse the xml locally it works fine but when upload the same script at the server it shows error. the code is

Note: I retrieved the $lng and $lat from the query string and it works fine locally.

$lng=$_GET['lng'];
$lat=$_GET['lat'];
$conn=new LoginSystem();
$conn->connect();
$dom = new DOMDocument("1.0");
$query="select catch_id,catch_details,image from mycatch where longitude='$lng' AND latitude='$lat'";
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}
header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)) {
  $node = $dom->createElement("mycatch");
  $node = $dom->appendChild($node);

  foreach ($row as $fieldname => $fieldvalue) {
       $child = $dom->createElement($fieldname);
       $child = $node->appendChild($child);
       $value = $dom->createTextNode($fieldvalue);
       $value = $child->appendChild($value);
  }
}

$conn->disconnect();
$xml_string = $dom->saveXML();
echo $xml_string;

On the server I get this error. And the document is also empty.....

This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

1 Answer 1

1

You will probably need to define a root element for the XML document.

At the moment you seem to have

<mycatch>
 <catch_id>1</catch_id>
 <catch_details>details</catch_details>
 <image>image</image>
</mycatch>
<mycatch>
 <catch_id>2</catch_id>
 <catch_details>details</catch_details>
 <image>image</image>
</mycatch>
...

But you don't have a root element such as:

<catches>
    <mycatch>
     <catch_id>1</catch_id>
     <catch_details>details</catch_details>
     <image>image</image>
    </mycatch>
    <mycatch>
     <catch_id>2</catch_id>
     <catch_details>details</catch_details>
     <image>image</image>
    </mycatch>
</catches>
Sign up to request clarification or add additional context in comments.

2 Comments

does't work on server i checked it locally it works but on server the document remains empty
So have you verified that the SQL query works on the server and returns some valid records?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.