0

My server.php file code is as below. I get an error saying "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."

$server->register('restaurant');
// Define the method as a PHP function


function restaurant($id) {
        $query = "SELECT * FROM `member_details` where Id=$id";
        $result = mysql_query($query);
        if(!$result )
        {
            die('Could not get data: ' . mysql_error());
        }       
        $xml_output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"; 
        $xml_output .= "<?xml-stylesheet type=\"text/xsl\" href=\"xsltDetails.xsl\"?>"; 
        $xml_output .= "<dataset>\n";
        for($x = 0 ; $x < mysql_num_rows($result) ; $x++){ 
        $row = mysql_fetch_assoc($result); 
        $xml_output .= "<entry>\n"; 
        $xml_output .= "<id>".$row['Id']."</id>\n"; 
        $xml_output .= "<name>".$row['Name']."</name>\n"; 
        $xml_output .= "<address>".$row['Address']."</address>\n"; 
        $xml_output .= "<postcode>".$row['Postcode']."</postcode>\n"; 
        $xml_output .= "<telephone>".$row['Telephone']."</telephone>\n"; 
        $xml_output .= "<opentime>".$row['OpenTime']."</opentime>\n";
        $xml_output .= "<restauranttype>".$row['ResType']."</restauranttype>\n"; 
        $xml_output .= "<licence>".$row['Licence']."</licence>\n"; 
        $xml_output .= "<keywords>".$row['Keywords']."</keywords>\n"; 
        $xml_output .= "<cuisine>".$row['Cuisine']."</cuisine>\n"; 
        $xml_output .= "</entry>\n";

        }
        $xml_output .= "</dataset>\n"; 
        return $xml_output;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
Ishara
  • 1
  • 1

1 Answers1

0

There must be an error in your XML somewhere. Please provide the output so that we can see more clearly where the problem is. Check if you are setting proper HTTP headers with header(). For XML output, it should be:

header( "Content-type: text/xml" );

Never use your own code for outputting XML when you have many good libraries at your disposal that do just that. Your code will be less prone to frustrating errors, much cleaner and easier to maintain. Please see this answer:

XML with PHP "echo" getting error "Extra content at the end of the document"

On additional note, make sure you are not feeding unsanitized POST data into your SQL query. That would be asking for a simple SQL injection attack:

http://en.wikipedia.org/wiki/SQL_injection

As in most cases, there are already good answers on Stack Overflow regarding this issue as well:

Is SQL Injection possible with POST?

Community
  • 1
  • 1