I'm really new to PHP and Im trying to append Nodes to XML using PHP.
This is my comments.php file:
<?php
$date = "http://jdrag.x10.mx/comments_file.xml";
$xml = simplexml_load_string($data);
$commentt = $xml->addChild("comment");
$name = $_POST["cname"];
$email = $_POST["cemail"];
$comment = $_POST["comment"];
$commentt->addChild("name", $name);
$commentt->addChild("email", $email);
$commentt->addChild("commentInside", $comment);
echo $xml->saveXML();
?>
My comments.html is:
<form action="comments.php" method="post">
Name: <input type="text" name="cname" />
Email: <input type="text" name="cemail" />
Comment: <input type="text" name="comment" />
<input type="submit" />
</form>
As you can see my XML file is simple the comments tag: http://jdrag.x10.mx/comments_file.xml
But when I submit the form I get this error:
Fatal error: Call to a member function addChild() on a non-object in /home/jdragx10/public_html/comments.php on line 5
And because i'm new to PHP I really don't know what it means or how to fix it. Thanks in advance to anyone who can fix my code.