0

我的 server.php 文件代码如下。我收到一条错误消息“此页面包含以下错误:

第 2 行第 1 列的错误:文档末尾的额外内容下面是第一个错误之前的页面呈现。”

$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);
?>
4

1 回答 1

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?

于 2013-10-07T07:32:08.363 回答