I have an AJAX chat that I am trying to edit. Originally, the users are stored in a php file. I'm trying to make it get users from a database.

Here's the original users.php file: http://pastebin.com/mgbQjHyK
Here's what I've tried: http://pastebin.com/kXgVLuyG

Can someone tell me what I'm doing wrong?
[hr]
Here's the error that it outputs:

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.
[theres nothing displayed after this]

Dani AI

Generated

The browser message "error on line 2 at column 1: Extra content at the end of the document" means the AJAX call returned XML that the parser started to accept but then found unexpected characters after (or before) the XML document. That almost always points to stray output being sent along with the XML — common culprits are UTF-8 BOMs, trailing whitespace or a stray ?> newline in included PHP files, accidental HTML/debug echoes, or PHP warnings/notices injected into the response. already fixed the variable issue; the remaining problem looks like an output-format problem rather than a DB query error.

Useful diagnostic checks:

  • View the raw response (browser “View Source” or curl -i) and confirm the first line is the XML declaration and that nothing appears before it and nothing appears after the closing root element.
  • Inspect the HTTP response headers in the Network panel (Content-Type should be an XML type).
  • Temporarily enable logging / show errors on a development copy to reveal hidden warnings; do not enable display_errors on production.

Practical fixes that resolve this class of error:

  • Save all PHP files (and includes) as UTF-8 without BOM. Many editors have an explicit “UTF-8 without BOM” save option.
  • Remove the closing ?> from pure-PHP include files (that avoids accidental trailing newlines).
  • Ensure no stray echo/HTML exists in included files and turn off display_errors in production so notices don’t corrupt XML.
  • As a safe output step, buffer and clean the output, strip a leading BOM if present, set the correct content-type, then echo the XML. Example pattern:
ob_start();
// generate XML into buffer
$xml = ob_get_clean();
if (substr($xml, 0, 3) === "\xEF\xBB\xBF") $xml = substr($xml, 3);
header('Content-Type: text/xml; charset=utf-8');
echo $xml;

This follows ’s suggestion to check included files and logging: once every included file is free of BOMs/whitespace and the raw response contains exactly one well-formed XML document, the parser error will disappear.

Recommended Answers

All 9 Replies

$users[$uid]['userName'] = '$username'; should be: $users[$uid]['userName'] = $username; No apostrophes around $username . Other than that, make sure that the AJAX_CHAT_XXX CONSTANTS you are using are defined.

Thanks and I fixed it, still have error though D:

The constants are correct.

are you including multiple files? If so, then check in the other files. After the corrections above, the file you posted should not be giving you any problems.

Also, check your error log file. If you are with a web host, ask them for the location of your log file.

one more suggestion - change:

$con = mysql_connect("localhost", "dannyf_admin", "mypasswordishere");
mysql_select_db("dannyf_test", $con);
$query = mysql_query("SELECT * FROM ajax_chat_users");
 
while($row = mysql_fetch_array($query)){

to:

$con = mysql_connect("localhost", "dannyf_admin", "mypasswordishere") or die(mysql_error());
mysql_select_db("dannyf_test", $con) or die(mysql_error());
$query = mysql_query("SELECT * FROM ajax_chat_users") or die(mysql_error());
 
while($row = mysql_fetch_assoc($query)){

I fixed all that, and I still have the problem.

If it helps find me a solution, this is the script I am using:

Thanks in advance for a good solution (and thanks to everyone who has replied so far :)).

use parse functions to changing the type of file system i am also develop project using scripting language. so you will get some idea from by give below website:
<URL SNIPPED>

I don't understand, toplinecar...

error on line 2 at column 1

that doesn't tell on which file. The fact that I don't see the constants defined on the file you posted indicates that there are file being included in the "main" file. Thus, you need to find out which file is the one that actually has the problem. Look at your php log file as indicated previously.

I will check the log file and see if anything is there. The error I get isn't your typical PHP/apache error message, this looks like it was outputted by something the creator of the script made.

Edit: nothing in the error log file from cPanel...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.