Violetchocolate Posted February 2, 2014 Share Posted February 2, 2014 (edited) <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! Edited February 2, 2014 by Violetchocolate Quote Link to comment https://forums.phpfreaks.com/topic/285880-need-some-help-here/ Share on other sites More sharing options...
cyberRobot Posted February 2, 2014 Share Posted February 2, 2014 So basically you want the <Player> element to always be added inside the <ArrayOfPlayer> element? If so, have you tried using something like this: http://www.php.net/manual/en/simplexmlelement.addchild.php Quote Link to comment https://forums.phpfreaks.com/topic/285880-need-some-help-here/#findComment-1467473 Share on other sites More sharing options...
Violetchocolate Posted February 3, 2014 Author Share Posted February 3, 2014 <?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"?> <ArrayOfPlayer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <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. Quote Link to comment https://forums.phpfreaks.com/topic/285880-need-some-help-here/#findComment-1467572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.