Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This page contains the following errors: error on line 1 at column 1: Document is empty

Tags:

php

xml

Im unable to find out the solution , please help. below is the code. Thanks in advance

<?php
if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $Lname = $_POST['lastName'];
    $num = $_POST['number'];
    echo $name.$Lname.$num;


    $xml = new SimpleXMLElement("<?xml version='1.0' encoding='UTF-8'?><Person></Person>");
    Header('Content-type:text/xml');
    $name = $xml->addChild('name',$name);
    $Lname = $xml->addChild('LastName',$Lname);
    $Number = $xml->addChild('Number',$num);


    print($xml->asXML());

}
?>

<!DOCTYPE html>
<head>
    <title>XML</title>
</head>
<body>
    <form method="post" action="" enctype= multipart/form-data>
        <input type="text" name="name" value="Name" required/>
        <input type="text" name="lastName" value="LName" required/>
        <input type="text" name="number" value="Number" required/>
        <input type="submit" value="send" name="submit"/>
    </form>
</body>
</html>

Im unable to find out the solution , please help. below is the code. Thanks in advance

like image 958
Muzammil Avatar asked Mar 08 '14 08:03

Muzammil


1 Answers

You need to wrap the <form> in the else part and remove the unneccesary echo statement.

The working code..

<?php
if(isset($_POST['submit'])){
    header('Content-type:text/xml');
    $name = $_POST['name'];
    $Lname = $_POST['lastName'];
    $num = $_POST['number'];
    //echo $name.$Lname.$num; //<---- Commented


    $xml = new SimpleXMLElement("<?xml version='1.0' encoding='UTF-8'?><Person></Person>");

    $name = $xml->addChild('name',$name);
    $Lname = $xml->addChild('LastName',$Lname);
    $Number = $xml->addChild('Number',$num);


    print($xml->asXML());

}
else
{
?>

<!DOCTYPE html>
<head>
    <title>XML</title>
</head>
<body>
<form method="post" action="" enctype= multipart/form-data>
    <input type="text" name="name" value="Name" required/>
    <input type="text" name="lastName" value="LName" required/>
    <input type="text" name="number" value="Number" required/>
    <input type="submit" value="send" name="submit"/>
</form>
</body>
</html>
<?php } ?>

OUTPUT :

<Person>
<name>Nameasdasd</name>
<LastName>LNameasdasd</LastName>
<Number>Number32424</Number>
</Person>
like image 113
Shankar Narayana Damodaran Avatar answered Nov 14 '22 23:11

Shankar Narayana Damodaran