Advertisement
Guest User

Untitled

a guest
May 17th, 2012
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1.  
  2. <?php
  3. if (isset($_POST['submitted'])) {//If the user submitted the form, then add to the XML file
  4.     //Load the scores XML file
  5.     $scores = new DOMDocument();
  6.     $scores -> load('scores.xml');
  7.  
  8.     //Get the <Games> tag
  9.     $games = $scores -> getElementsByTagName('Games');
  10.  
  11.     //Create the new <Game> tag (Could probably be done better by first placing everything in an array or something)
  12.     $newGame = $scores -> createElement("Game");
  13.     $newGame -> appendChild($scores -> createElement("Time", $_POST['time']));
  14.     $newGame -> appendChild($scores -> createElement("Score", $_POST['score']));
  15.     $newGame -> appendChild($scores -> createElement("Row", $_POST['row']));
  16.  
  17.     //Add the new <Game> tag under the <Games> tag
  18.     $games -> item(0) -> appendChild($newGame);
  19.  
  20.     //Save again
  21.     $scores -> save('scores.xml');
  22.  
  23.     echo "New game added.";
  24. }
  25. ?>
  26. <form method="post" action="">
  27.     Time:
  28.     <br>
  29.     <input type="text" name="time">
  30.     <br>
  31.  
  32.     Row:
  33.     <br>
  34.     <input type="text" name="row">
  35.     <br>
  36.  
  37.     Score:
  38.     <br>
  39.     <input type="text" name="score">
  40.     <br>
  41.  
  42.     <input type="submit" name="submitted" name="Add new row">
  43. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement