I'm having hard time to do a php post to a XML data here is my form:
<form action="../xml/data.php" method"post">
<p>Name</p>
<input name='name' required><br>
<p>ID</p>
<input name"id" required>
<input type='submit' value ="submit" name="submit">
</form>
here is my PHP code:
<?php
$s_id=$_POST['id'];
$s_name=$_POST['name'];
$xml = new DOMDocument("1.0");
$student = $xml -> createElement("student");
$xml -> appendChild($student);
$id_value = $xml ->createTextNode("$s_id");
$id -> appendChild($id_value);
$name = $xml -> createElement("name");
$student -> appendChild($name);
$name_value=$xml->createTextNode("$s_name");
$name->appendChild($name_value);
$xml ->formatOutput = true;
$xml -> save("mydata.xml");
?>
But it doesn't make the mydata.xml file and not working :s not sure what i'm doing wrong here
You're missing an =
in your form tag:
<form action="../xml/data.php" method"post">
should be
<form action="../xml/data.php" method="post">
And also here
<input name"id" required>
should be
<input name="id" required>
@PHPglue is correct too - $id -> appendChild($id_value);
should presumably be $student -> appendChild($id_value);
.
You are missing a few equals signs in your form code:
<form action="../xml/data.php" method"post">
and
<input name"id" required>
should be:
<form action="../xml/data.php" method="post">
and
<input name="id" required>