html - PHP/XML - Fixing writing script -


im live, a new programmer and student, I'm currently following a short tutorial, reading an XML file I'm demonstrating this is one thing with PHP, which I want to do myself, in my PHP script, writing data in my PHP script, using a form in HTML, my script and form like this Looks like:

  & lt;? PP resonance ('script start'); /// To ensure that the script works only when ($ _SERVER ["REQUEST_METHOD"] == "POST") {echo ('-post accept'); // Load XML file variable $ xml = simplexml_load_file ("phptest3.xml"); Echo ('-XML Load'); // Convert Rupees $ name = $ _POST ['name']; $ Age = $ _POST ['age']; $ Sex = $ _POST ['gender']; $ Comment = $ _POST ['comment']; Echo ('-wars connect'); // XSS / Injections function is not necessary to prevent test_input ($ data) {$ data = trim ($ data) to bar those objects; $ Data = stripesal ($ data); $ Data = htmlspecialchars ($ data); $ Return data; Echo ('-injection stripped'); // Create new children in XML files and add XML related entries to the data $ xml- & gt; People [0]; $ Xml- & gt; Mass & gt; AddChild ('person'); $ Xml- & gt; Person [0]; $ Xml- & gt; Person- & gt; Add Child ('name', $ name); $ Xml- & gt; Person- & gt; Add Child ('age', $ age); $ Xml- & gt; Person- & gt; Add Child ('Sex', $ Sex); $ Xml- & gt; Person- & gt; Plus child ('comment', $ comment); Echo ('-data entered'); // Save the current data to the XML file ... $ xml- & gt; Savexml ('phptest3.xml'); Echo ('-service'); } Echo ('-pcp end'.); ? & Gt;   

While my XML looks like this

  & lt ;? Xml version = "1.0"? & Gt; & Lt; People & gt; & Lt; Person & gt; & Lt; Name & gt; Lighty & lt; / Name & gt; & Lt; Age & gt; 17 & lt; / Age & gt; & Lt; Sex & gt; M & lt; / Sex & gt; & Lt; Comment & gt; IETS & lt; / Comment & gt; & Lt; Name & gt; IETS & lt; / Name & gt; & Lt; Age & gt; 75 & lt; / Age & gt; & Lt; Sex & gt; F. & lt; / Sex & gt; & Lt; Comment & gt; igjk & lt; / Comment & gt; & Lt; Name & gt; IETS & lt; / Name & gt; & Lt; Age & gt; 75 & lt; / Age & gt; & Lt; Sex & gt; M & lt; / Sex & gt; & Lt; Comment & gt; gergsrh & lt; / Comment & gt; & Lt; / Person & gt; & Lt; / People & gt; Now, it now inserts the data, but it puts it where it should be placed:   

(). You can use saveXML instead. $ _ POST ['name'] = 'testName'; $ _POST ['age'] = '15'; $ _POST ['gender'] = 'F'; $ _POST ['comment'] = 'test comment'; // Load XML file variable $ xml = simplexml_load_file ("test.xml"); // Converting forms $ name = $ _POST ['name']; $ Age = $ _POST ['age']; $ Sex = $ _POST ['gender']; $ Comment = $ _POST ['comment']; // Create new children in XML file and add XML related entries to the data $ xml- & gt; Program = ""; $ Xml- & gt; Program- & gt; Add child ('name', $ name); $ Xml- & gt; Program- & gt; Add Child ('Age', $ Age); $ Xml- & gt; Program- & gt; Junk Child ('Sex', $ Sex); $ Xml- & gt; Program- & gt; Add child ('comment', $ comment); // Save existing data to XML files ... $ xml- & gt; Save XML ('test.xml');

test.xml:

  & lt ;? Xml version = "1.0"? & Gt; & Lt; People & gt; & Lt; Person & gt; & Lt; Name & gt; Lighty & lt; / Name & gt; & Lt; Age & gt; 17 & lt; / Age & gt; & Lt; Sex & gt; M & lt; / Sex & gt; & Lt; Comment & gt; eyewayayaya & lt; / Comment & gt; & Lt; / Person & gt; & Lt; Name & gt; Trial name & lt; / Name & gt; & Lt; Age & gt; 15 & lt; / Age & gt; Gender & gt; F. & lt; / Gender & gt; & Lt; Comment & gt; Test comment & lt; / Comment & gt; & Lt; / Program & gt; & Lt; / People & gt; ; Edit:  

Did you say that you got an error, why did not you post it? Because when I tried to execute your script I got a clear error Fatal error: Call the undefined method SimpleXMLElement :: save () .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -