Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST['submitted'])) {//If the user submitted the form, then add to the XML file
- //Load the scores XML file
- $scores = new DOMDocument();
- $scores -> load('scores.xml');
- //Get the <Games> tag
- $games = $scores -> getElementsByTagName('Games');
- //Create the new <Game> tag (Could probably be done better by first placing everything in an array or something)
- $newGame = $scores -> createElement("Game");
- $newGame -> appendChild($scores -> createElement("Time", $_POST['time']));
- $newGame -> appendChild($scores -> createElement("Score", $_POST['score']));
- $newGame -> appendChild($scores -> createElement("Row", $_POST['row']));
- //Add the new <Game> tag under the <Games> tag
- $games -> item(0) -> appendChild($newGame);
- //Save again
- $scores -> save('scores.xml');
- echo "New game added.";
- }
- ?>
- <form method="post" action="">
- Time:
- <br>
- <input type="text" name="time">
- <br>
- Row:
- <br>
- <input type="text" name="row">
- <br>
- Score:
- <br>
- <input type="text" name="score">
- <br>
- <input type="submit" name="submitted" name="Add new row">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement