HTML: Save text on server?

5 posts Page 1 of 1
Contributors
User avatar
dj1437
VIP - Donator
VIP - Donator
Posts: 504
Joined: Tue Dec 21, 2010 2:02 am

HTML: Save text on server?
dj1437
Hello. I need help with a little project:

There's a website with a textbox and a submit button. When the user clicks the submit button the text should be saved into a txt file on the server. I remember doing such a thing a very long time ago and php was involved too but now I forgot it and there don't seem to be any good answers on google either. Can you help with it?
This is a signature.
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: HTML: Save text on server?
Filip
Hello,


This code should work:
Code: Select all
<?
if ($_POST && $_POST['nameoffield']!="") {
    file_put_contents("path/to/file.txt", $_POST['nameoffield']."\n", FILE_APPEND);
}
?>
<form method="post">
<input type="text" name="nameoffield" />
<input type="submit" value="Submit" />
</form>
KR
-Filip
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
dj1437
VIP - Donator
VIP - Donator
Posts: 504
Joined: Tue Dec 21, 2010 2:02 am

Re: HTML: Save text on server?
dj1437
For some reason, the text file stays empty. The text file is in the same folder as the index.php so I set the path to something like 'file.txt'
This is a signature.
User avatar
dj1437
VIP - Donator
VIP - Donator
Posts: 504
Joined: Tue Dec 21, 2010 2:02 am

Re: HTML: Save text on server?
dj1437
dj1437 wrote:
For some reason, the text file stays empty. The text file is in the same folder as the index.php so I set the path to something like 'file.txt'
Edit: forgot to CHMOD it! Working now! Thanks a lot.
This is a signature.
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: HTML: Save text on server?
Filip
You're welcome,

If you need any help, feel free to ask.

-Filip
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
5 posts Page 1 of 1
Return to “Help & Support”