首页 > 解决方案 > 第 5 行第 1 列的错误:文档末尾的额外内容

问题描述

为什么我会收到以下错误:

此页面包含以下错误: 第 5 行第 1 列的错误:文档末尾的额外内容 下面是页面的呈现直到第一个错误。

这是我的代码:

<?php 

    @header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$dir   = substr(trim($_REQUEST['Body']),0,3);
$msg   = substr(trim($_REQUEST['Body']),3);
$phone =  '0'.substr(trim($_REQUEST['From']),4);

 if($dir == 'PRV'){
        process_PreVoting($phone,$date,$msg);
    }

function process_PreVoting($phone,$date,$msg){
        //$mysqliobject = new dbobject();
        global $mysqli;
        $details = explode(";",$msg);
        $officer_id = $details[1];
        $userpassword = $details[2];
        $lga =  $details[3];
        $ward = $details[4];
        $poll_unit = $details[5];
        $total_queue = $details[6];
        if($total_queue=='')$total_queue=0;
        $comments = $details[7];
        $device_entry_date = $details[8];
        //$resp = $mysqliobject->getcheckdetails($officer_id,$userpassword);
        $sql  = "SELECT * FROM master where phoneNo = '$phone' OR phonetwo = '$phone'";
              $st   =  mysqli_query($mysqli, $sql);
              $resp  =  mysqli_num_rows($st);
             //$PtaW =  mysqli_fetch_assoc($st);
        if($resp > 0)
        {
            // check if record already exists
            $sqls = mysqli_query($mysqli,"SELECT officer_code FROM pre_voting_info WHERE officer_code='$officer_id'");
            $count = mysqli_num_rows($sqls);
            if($count > 0)
            {
            mysqli_query($mysqli,"update pre_voting_info set total_queue='$total_queue', comments='$comments', modify_entry_date='$device_entry_date' WHERE officer_code='$officer_id'");
            }
            else
            {

$resps = mysqli_query($mysqli,"insert into pre_voting_info(pu_name,ward_name,lga_name,total_queue,comments,entry_date,device_entry_date,officer_code) values ('$poll_unit','$ward','$lga','$total_queue','$comments','$device_entry_date','$device_entry_date','$officer_id')");

                if($resps) {
                    return "PreVoting Post Successfully Added";
                }
                else {
            return "Error, could not add PreVoting Details. ".$mysqli->error;
                }

            $my_file = "echolog.txt";
            $handle = fopen($my_file, 'a') or die('Cannot open file:  '.$my_file);
            fwrite($handle, "PRE-VOTING SQL: ".$sql);
            fclose($handle);

            }


        }else{

            return "Invalid User Credentails: ".$mysqli->error;
            $date = date('Y-m-d H:i');
            mysqli_query($mysqli,"insert into logtable (phoneNo,title,logMsg,pu,logDate) values ('$phone','Accreditation','$info','$poll_unit','$date')");

        }

    }//Function close

当我在浏览器上预览我的源代码时,它输出的唯一内容是:

<?xml version="1.0" encoding="UTF-8"?>

标签: phpxml

解决方案


必须有一些内容才能成为有效的 xml 文档,例如这样就足够了:

<?xml version="1.0" encoding="UTF-8"?>
<root></root>

推荐阅读