HazelRah Posted January 13, 2008 Share Posted January 13, 2008 Hi!. HazelRah here. I need, a text form that when someone writes in it and clicks Submit, the data on that form gets written to a .txt file called items.txt. Is this possible?. I really need it. Thanks!. ~ HazelRah Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/ Share on other sites More sharing options...
pocobueno1388 Posted January 13, 2008 Share Posted January 13, 2008 Yes, it's possible. http://www.tizag.com/phpT/fileopen.php http://www.tizag.com/phpT/filewrite.php **** http://www.tizag.com/phpT/fileclose.php Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438025 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 Hi!. Thankyou for replying so soon. I'm a bit confused here, am i meant to link a page to filewrite.php, or include it?. I'm pretty noobish at PHP. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438026 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 Well if you want a specific solution you'll need to post the HTML that you're using for your form and tell us how you want the data to be formatted in the file. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438028 Share on other sites More sharing options...
Hypnos Posted January 13, 2008 Share Posted January 13, 2008 Your form should have "action=" set to the script that writes the txt file. Use fwrite to append the txt file. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438032 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 <label> <div align="center">Make an ITEM To put in the Bank!.<br> <br> <input name="textfield" type="text" id="textfield" value=""> <br> <br> <input type="submit" name="button" id="button" value="Submit"> </div> </label> I just want, so when someone writes something in the textfield, and presses "Submit", the words in the textfield get put on a text file called items.txt. I want it to be formatted like this: word1 word2 word3 thanks!. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438034 Share on other sites More sharing options...
trq Posted January 13, 2008 Share Posted January 13, 2008 Take a look at the links provided. Were not here to do it for you. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438036 Share on other sites More sharing options...
Hypnos Posted January 13, 2008 Share Posted January 13, 2008 You're missing a <form> tag. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438037 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 Take a look at the links provided. Were not here to do it for you. I have looked! Im here because i dont understand it. If i did understand it, i wouldn't be here Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438041 Share on other sites More sharing options...
Hypnos Posted January 13, 2008 Share Posted January 13, 2008 http://www.w3schools.com/php/php_forms.asp http://us3.php.net/fwrite Forums aren't for teaching you everything. For what you have and what you need it to be, someone here would either have to write it for you, or write you a 2 page essay. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438046 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 Take a look at the links provided. Were not here to do it for you. Ah but you're forgetting that some of us are really bored and have nothing better to do =P Firstly, I'm not sure how valid this HTML is but the following should work: <label> <div align="center">Make an ITEM To put in the Bank!.<br> <br> <form action="script.php" method="post"> <input name="textfield" type="text" id="textfield" value=""> <br> <br> <input type="submit" name="button" id="button" value="Submit"> </form> </div> </label> Then in script.php: <?php if(isset($_POST['button'])) { $fname = 'items.txt'; $data = str_replace(' ', "\n", $_POST['textfield']); if(version_compare(phpversion(), '5.0.0', '>=')) { file_put_contents($fname, $data); } else { $h = fopen($fname, 'a'); fwrite($h, $data); fclose($h); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438051 Share on other sites More sharing options...
SirChick Posted January 13, 2008 Share Posted January 13, 2008 Take a look at the links provided. Were not here to do it for you. I have looked! Im here because i dont understand it. If i did understand it, i wouldn't be here If you can't understand some thing that is solely to educate you then you need to buy a book on it and read thoroughly. You won't understand the way any one here explains it any more than a site that explains it most probably better than we could anyway. If people make entire scripts for you.. ya won't understand it but will just take it for granted. Which isn't smart. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438053 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 Take a look at the links provided. Were not here to do it for you. Ah but you're forgetting that some of us are really bored and have nothing better to do =P Firstly, I'm not sure how valid this HTML is but the following should work: <label> <div align="center">Make an ITEM To put in the Bank!.<br> <br> <form action="script.php" method="post"> <input name="textfield" type="text" id="textfield" value=""> <br> <br> <input type="submit" name="button" id="button" value="Submit"> </form> </div> </label> Then in script.php: <?php if(isset($_POST['button'])) { $fname = 'items.txt'; $data = str_replace(' ', "\n", $_POST['textfield']); if(version_compare(phpversion(), '5.0.0', '>=')) { file_put_contents($fname, $data); } else { $h = fopen($fname, 'a'); fwrite($h, $data); fclose($h); } } ?> thankyou!!! EDIT: I just tried it, it went to script.php.. (blank page) and, i opened the .txt file, its empty :S Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438067 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 Where is the .txt file stored? It needs to be in the same directory as script.php and be writeable by everyone (777 permissions most likely). Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438077 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 it is writeable, and in same directory as script.php Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438079 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 OK, at the top of script.php (under the <?php bit though) can you put: var_dump($_POST); and tell me what you get? Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438081 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 Total blankness Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438086 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 OK, I have no idea what's going on now. Try putting: echo "I can has cheezeburger"; at the top as well (make sure var_dump() and echo aren't inside the if() statement!) Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438101 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 OK, I have no idea what's going on now. Try putting: echo "I can has cheezeburger"; at the top as well (make sure var_dump() and echo aren't inside the if() statement!) ITS NOT SHOWING LOL Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438106 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 Uh... Is your site on the internet anywhere so I can have a look myself? Or can you post what you've got so far in script.php and your HTML file. Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438108 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 http://inferno.watershipdown.parahosting.net/Egg/3.php Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438111 Share on other sites More sharing options...
HazelRah Posted January 13, 2008 Author Share Posted January 13, 2008 Thanks! i finally got it working... Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438115 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 Awesome. You can remove the echo and var_dump() now and replace it with a message like 'Success!' or redirect back to the original file with: header("Location: 3.php"); Quote Link to comment https://forums.phpfreaks.com/topic/85826-solved-is-this-possible/#findComment-438131 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.