0

i have resently set up apache and php on a new server,but my php code that was rendering xml on my old server does not render on the new one below is the error display.Please someone help me:

XML Parsing Error: XML or text declaration not at start of entity
Location: `http://192.168.1.200/file.php`
Line Number 4, Column 1:<?xml version = "1.0" ?><rows><row id = '85'><cell>  </cell><cell> 85 </cell><cell image='folder.gif'> 55 </cell><cell> 61 </cell><cell> 2013-07-27 14:29:15 </cell><cell> ndegwa22@googlemail.com </cell><cell> salland@nts.nl </cell>
^

My Code

<?php     
            require("config.php");
            header("Content-type:text/xml");
            echo "<?xml version = \"1.0\" ?>";
            echo "<rows>";

            $qry = "SELECT * FROM tickets WHERE parent_id = 0 ORDER BY message_id DESC";
            $res = mysql_query($qry) or die(mysql_error().$qry);

            while ($row = mysql_fetch_array($res))
            {
                echo "<row id = '{$row["id"]}'>";
                    echo "<cell> {$row["id"]} </cell>";
                    echo "<cell image='folder.gif'> {$row["ticket_id"]} </cell>";
                    echo "<cell> {$row["message_id"]} </cell>";
                    echo "<cell> {$row["date_time"]} </cell>";
                    echo "<cell> {$row["from_email"]} </cell>";
                    echo "<cell> {$row["to_email"]} </cell>";
                    echo "<cell> ".xmlEscape($row["subject"])." </cell>";  

                    echo "<cell><![CDATA[";

                        $ar = explode(";",$row["attachment"]);
                        foreach($ar as $key=>$value)
                        {
                            echo "<a target='_blank' href='Mail/attachments/{$value}'>{$value} </a>  &nbsp;";
                        }

                    echo "]]></cell>";
                    echo "<cell> {$row["eid"]}</cell>";
                    echo "<cell> {$row["email_status"]}</cell>";
                    echo "<cell> {$row["ticket_status"]}</cell>";
                    echo "<cell> {$row["entry_datetime"]}</cell>";

                    getChildMailXml($row["id"]);

                echo "</row>";
            }

            echo "</rows>";

?>
hakre
  • 193,403
  • 52
  • 435
  • 836

2 Answers2

1

There should not be any space, line or printing output before header("Content-type:text/xml"); echo "<?xml version=\"1.0\" ?>"; Place require("config.php"); file after these lines.

<?php
    header("Content-type:text/xml");
    echo "<?xml version = \"1.0\" ?>";
    require("config.php");
    echo "<rows>";
    echo "<row id='1'><cell>1</cell></row>";
    echo "</rows>";
?>

There should not be any output in config.php file

Saranya Sadhasivam
  • 1,296
  • 6
  • 9
  • thnx user2314588.Helped alot One more thing i needed to remove the white spaces then remove ?> in my config.php it caused all my problems – Martin Mundia Jul 30 '13 at 10:58
0

According to the error message:

XML Parsing Error: XML or text declaration not at start of entity Location: ...

Line Number 4, Column 1: <?xml version = "1.0" ?><rows><row id = '85'><cell>  </cell><cell> 85 </cell><cell image='folder.gif'> 55 </cell><cell> 61 </cell><cell> 2013-07-27 14:29:15 </cell><cell> ndegwa22@googlemail.com </cell><cell> salland@nts.nl </cell>
                         ^

You are outputting the XML declaration (<?xml version = "1.0" ?>) on line number four. If you output the XML declaration you must output it at the first line, which is line number one (- not four (!)).

Fix the output of your script to output it at the first line and first column and you should be fine.

From the code you've shown it is not visible where the other lines are introduced, but you can rest assured, that whatever gives the error message is not lying therefore, rest assured this is actually line four not the first line and you need to fix this.

If you don't have any kind of understanding where and why those other lines are being introduced, please learn about how PHP outputs data to the client. As input and output is such a fundamental domain in programming, I suggest you start your learning with the introduction and then work through all the first chapters of the PHP manual:

If you want to add some interactive learning next to reading only, there is the PHP track on codecademy available:

hakre
  • 193,403
  • 52
  • 435
  • 836
  • thnx hakre.Remeber i said the code i wrote worked on my old server.Just configured a new oneto work with dhtmlx...I will go back to a beginners course in php thnx for URL – Martin Mundia Jul 30 '13 at 11:00
  • Well, that's merely a configuration issue. You can also compare the output of phpinfo() on both systems. Check for output related settings. The topic is quite large and from your code alone it's hard to say, so merely something to trouble-shoot. – hakre Jul 30 '13 at 11:16