I'm trying to get a demo of XMLHTTPRequest off the ground for a project I'm working on. Using some simple sample code, Firefox tells me the following:

XML Parsing Error: xml processing instruction not at start of external entity

Here's the PHP/XML:

<?
	header('Content-Type: text/xml');

function nameInUse($thename)
{  
	$q = "SELECT id, username FROM users WHERE username='$thename'";
	if(mysql_num_rows(mysql_query($q)))
		return 1;
	else
		return 0;
}
?>
<!-- XML BELOW -->
<?
	echo '<?xml version="1.0"?>';
?>
	<response>
		<method>verifyDesiredUsername</method>
		<result><? echo nameInUse($_GET['n']); ?></result>
	</response>

For the life of me I cannot figure out what is wrong. The above code is supplied as part of the tutorial (essentially.. tweaked it a bit) and others have verified that it works. However, I'm still at a loss. :/ Any help?

    Dont use short tags.

    Use <?php instead of <?

    XML gets confused.

      It's the XML comment. Put that after the processing instruction Firefox cites. (XML comments are XML - so "XML below" should be "XML starts here", and then the mistake of placing it before the XML processing instruction becomes obvious!)

        I appreciate the input. That was the problem. 🙂 And onion.. thanks for the info, mate!

          Write a Reply...