dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Writing in Xml through PHP error

  1. #1
    Join Date
    May 2014
    Posts
    3

    Exclamation Writing in Xml through PHP error

    Hi, I'm a student who's learning PHP and XML and have found an error which baffles even my teacher. So I was hoping you guys could help me out.

    Through this form, I want to register and store users on an XML file:


    <div id="Sign-Up">
    <fieldset style="width:21%">
    <legend>Registreren</legend>
    <table border="0">
    <form action="register.php" method="post">
    <tr>
    <td>Name</td> <td> <input type="text" name="name"></td>
    </tr>
    <tr>
    <td>Password</td><td> <input type="password" name="pass"></td>
    </tr>
    <tr>
    <td>Confirm Password </td><td> <input type="password" name="cpass"></td>
    </tr>
    <tr>
    <td><input id="button" name="submit" value="Registreer" type="submit"></td>
    </tr>
    </form>
    </table>
    </fieldset>
    </div>

    after which it goes to the register.php file which has:

    <?php

    if(isset($_POST["name"]) && isset($_POST["pass"])) {
    $filename = "Users.xml";
    $file = simplexml_load_file($filename);
    $user = $file->addChild("user");
    $user->addChild("naam", $_POST["name"]);
    $user->addChild("password", $_POST["pass"]);

    $file_put_contents($filename,$file->asXml());
    }
    else {
    echo "voeg iet in";
    }

    ?>

    And when I try to run it (using Xampp) I get this error:

    Notice: Undefined variable: file_put_contents in C:\xampp\htdocs\register.php on line 10

    Fatal error: Function name must be a string in C:\xampp\htdocs\register.php on line 10


    I have no idea what to do

  2. #2
    Join Date
    May 2014
    Posts
    3
    $file_put_contents($filename,$file->asXml());

    is line 10

  3. #3
    Join Date
    May 2014
    Posts
    3
    It's already fixed, the '$' was wrong

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    The method name is asXML not asXml. Slap your teacher for not enforcing standard practice.

    You can use asXML() in place of file_put_contents().

    http://us1.php.net/manual/en/simplexmlelement.asxml.php
    Last edited by ShrineDesigns; 05-19-2014 at 06:18 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles