Jump to content

Need some help here


Violetchocolate

Recommended Posts

<form name="form1" method="post" action="form.php?saving=1">
  <textarea name="data" cols="100" rows="10">
  <?php
    $file = "example.txt";
{  
      $file = file_get_contents("$file");
      echo $file;  
$url = 'background.jpg';
    }  
  ?>


  </textarea>
  <br>
  <input type="submit" value="Save">
</form>
 

--- FORM.php ----
 <?php
  $saving = $_REQUEST['saving'];
  if ($saving == 1) {
    $data = $_POST['data'];
    $file = "C:\Users\Rickard\Desktop\RustServ++\Save\RustPP\whitelist.xml";


    $fp = fopen($file, "a+") or die("Couldn't open $file for writing!");
    fwrite($fp, $data) or die("Couldn't write values to file!");
    fclose($fp);
    echo "Saved to $file successfully!";
  }
?>

Okey, But when they submit their value they put into the next box is supposed to save in the .xml file. Yes it does works perfectly, but ! 

It's supposed to leave This at the end of the .xml file

</ArrayOfPlayer>

So it looks like this complete

 

  <Player>
    <DisplayName>Anonymous</DisplayName>
    <UserID>76561197960484366</UserID>
  </Player>
</ArrayOfPlayer>

But i cant get it to work, so when a new player signs up it always leaves the </ArrayOfPlayer> at the end. Can anyone give me some tips how to fix this? Oh and the ArryOfPlayer Is at the very end of the .xml file Always!

Link to comment
https://forums.phpfreaks.com/topic/285880-need-some-help-here/
Share on other sites

<?php
if( isset( $_POST['submit'] ) )
{
$xml_file = fopen( "data.xml", "wb+ /r+n");
fwrite( $xml_file, "<?xml version='1.0' encoding='utf-8' ?>" );
fwrite( $xml_file, "<Player>" );
fwrite( $xml_file, "<DisplayName>" );
fwrite( $xml_file, $_POST['DisplayName'] );
fwrite( $xml_file, "</DisplayName>" );
fwrite( $xml_file, "</UserID>" );
fwrite( $xml_file, $_POST['UserID'] );
fwrite( $xml_file, "</Player>" );
fwrite( $xml_file, $_POST['/player'] );
}
?>
<form enctype="multipart/form-data" action="index.php" method="post" autocomplete="true">
    <p><input type="text" name="DisplayName" placeholder="DisplayName" /></p>
    <p><input type="text" name="UserID" placeholder="UserID" /></textarea></p>
    <p><input type="submit" value="Submit" name="register" /></p>
</form>
 
I have no clue what i'm doing... Trying to get it to generate this in a existing XML file
 
<?xml version="1.0" encoding="utf-8"?>
  <Player>
    <DisplayName>Devil</DisplayName>
    <UserID>76561197960328004</UserID>
  </Player>
  <Player>
    <DisplayName>weronim</DisplayName>
    <UserID>76561197960468288</UserID>
  </Player>
 </ArrayOfPlayer> 
 
With the  </ArrayOfPlayer>  at the very end of the .xml file ''ALWAYS''

The data from TextField One and Two goes into <DisplayName>DATAONE</Displayname>

TextField Two  <UserID>DATATWO</UserID>

 

And it has to be a space between each new like like in the example. I have tryed for a damn time now '' I dont know php at all i just follow alot of tutorials in hope for the best while trying to understand what it does and why it does so. Damn hard to get php + xml together.

 

Can anyone please help me.

Link to comment
https://forums.phpfreaks.com/topic/285880-need-some-help-here/#findComment-1467572
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.