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
You need to wrap the <form>
in the else
part and remove the unneccesary echo
statement.
<?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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With