3

whenever I use the following code in PHP files , it gives me the error (Error: XML or text declaration not at start of entity Source)

<?xml version='1.0' encoding='utf-8'?>

I don't know what could be the solution

please help

Thanks in advance

<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><records>15</records><total>1</total><row id='18'><cell>18</cell><cell>2011-9-13</cell><cell>AL</cell><cell>2011-10-19</cell><cell>2011-10-21</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='17'><cell>17</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-19</cell><cell>2011-5-19</cell><cell>1</cell><cell></cell><cell></cell><cell>Approved</cell><cell>Davinder</cell><cell>Kavita y</cell></row><row id='16'><cell>16</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-24</cell><cell>2011-5-24</cell><cell>1</cell><cell></cell><cell></cell><cell>Approved</cell><cell></cell><cell>Kavita y</cell></row><row id='15'><cell>15</cell><cell>2011-5-26</cell><cell>AL</cell><cell>2011-7-08</cell><cell>2011-7-12</cell><cell>0</cell><cell></cell><cell></cell><cell>Disapproved</cell><cell></cell><cell>Kavita y</cell></row><row id='14'><cell>14</cell><cell>2011-5-25</cell><cell>AL</cell><cell>2011-6-30</cell><cell>2011-7-02</cell><cell>3</cell><cell></cell><cell></cell><cell>Approved</cell><cell></cell><cell>Kavita y</cell></row><row id='13'><cell>13</cell><cell>2011-9-14</cell><cell>CL</cell><cell>2011-6-15</cell><cell>2011-6-15</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='12'><cell>12</cell><cell>2011-5-25</cell><cell>CL</cell><cell>2011-6-10</cell><cell>2011-6-12</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='11'><cell>11</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-17</cell><cell>4</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='10'><cell>10</cell><cell>2011-5-25</cell><cell>CL</cell><cell>2011-6-03</cell><cell>2011-6-05</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='9'><cell>9</cell><cell>2011-5-26</cell><cell>SL</cell><cell>2011-5-18</cell><cell>2011-5-22</cell><cell>5</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='8'><cell>8</cell><cell>2011-5-24</cell><cell>AL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>0</cell><cell></cell><cell></cell><cell>Disapproved</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='7'><cell>7</cell><cell>2011-5-24</cell><cell>CL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='4'><cell>4</cell><cell>2011-9-14</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='3'><cell>3</cell><cell>2011-5-24</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='1'><cell>1</cell><cell>2011-5-24</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-22</cell><cell>0</cell><cell>dd</cell><cell>remarks</cell><cell>Disapproved</cell><cell>mohan</cell><cell>Davinder Singh</cell></row></rows>

and the php code

header("Content-type: text/xml;charset=utf-8");

$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .=  "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<records>".$count."</records>";

$s .= "<total>".$total_pages."</total>";


// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {


    $s .= "<row id='". $row['fld_id']."'>";

    $s .= "<cell>". $row['fld_id']."</cell>";   
    $s .= "<cell><![CDATA[". getDepartmentName($row['deptSr'])."]]></cell>";
    $s .= "<cell>". $row['email']."</cell>";
    $s .= "<cell>". $row['fname']."</cell>";
    $s .= "<cell>". $row['lname']."</cell>";
    $s .= "<cell>". $row['password']."</cell>";

    $s .= "<cell>". listlevel($row['level'])."</cell>"; 
    $s .= "<cell>". date('Y-m-d G:i:s', $row['date_create'])."</cell>";
    $s .= "<cell>". date('Y-m-d G:i:s', $row['last_login'])."</cell>";  
    $s .= "<cell>". $row['ip_addr']."</cell>";
    $s .= "<cell>". $row['dob']."</cell>";  
    $s .= "<cell>". $row['street']."</cell>";       
    $s .= "<cell>". $row['phone_mob']."</cell>";        
    $s .= "<cell>". $row['phone_home']."</cell>";   
    $s .= "<cell>". liststatus($row['fld_enabled'])."</cell>";  

    $s .= "</row>";
}
$s .= "</rows>"; 

echo $s;
9
  • what is causing the error? PHP or some other tools? Is there any PHP code involved at all? Commented Nov 16, 2011 at 8:31
  • the records are coming from the database, and php gives the output in xml format. It's working on the one server, but no luck on the rest Commented Nov 16, 2011 at 8:33
  • ok, but what is giving the error? The browser? Or PHP? A certain piece of code? If it's not short_open_tag we need more information. Is there any whitespace or ByteOrder Marks before the XML prolog? Or are there any dangling prologs somewhere? Commented Nov 16, 2011 at 8:36
  • This thing here: <?xml version="1.0" encoding="utf-8"?> is a prolog. There should be only one of it. Also can you please check the source code of the result page that is giving you the error and make sure there is no whitespace or funny characters before the prolog. Commented Nov 16, 2011 at 8:43
  • 1
    let us continue this discussion in chat Commented Nov 16, 2011 at 8:47

1 Answer 1

2

XML or text declaration not at start of entity indicates that the prolog isn’t the first line in the output. Most likely, a blank line is somehow finding its way into your output. This error isn’t unique to WordPress; however, as I mentioned in my comment, I did a search for the error message on Google and WordPress comes up in a lot of the results. If you’re not using WordPress, kindly disregard the remainder of this answer.

Disclaimer: I know nothing about WordPress so I’m reluctant to answer in that capacity; however, since there are no other answers as of this writing, I’ll simply show you what I’ve found on the subject.

If you are using WordPress, you may attract better answers by adding the WordPress tag to your question. There’s no guarantee, but it could draw the attention of those more knowledgeable than myself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.