How do I use php so that when a user presses a specific button, they can write to a specific .txt file?

Well, you should learn about using forms with PHP with regards to your comment. If you read that tutorial fully, it should answer all of your questions about forms and php.

Well, you should learn about using forms with PHP, with regards to your comment. If you read that tutorial fully, it should answer all of your questions about forms and php. As far as getting it to write to a different text file, since you seem worried about "uploading all those pages", you'll be happy to know there's an easy solution!

There's a function called file_put_contents, which will create or write into a file. Since you're new(ish) to PHP, here's an example: This puts the contents of the $text variable into the file with the name stored in $file. Reading from a file is similarly easy, with file_get_contents.

Assuming the file hello. Txt exists from before and has the same contents, you can use the following code to read from the file and output its contents: That will show the contents of $file. Now, moving into the specifics of your question, if your form sets a "to" and a "from" GET variable where "to" is your username already, then the following code would write the value in a "message" GET variable into the file based on the pattern you gave: This fetches our variables from the GET array, sanitizes them to some extent, sets the file name, and writes the message to the file.

If you have any questions about specific parts of this or you'd like me to go into more detail, please feel free to ask!

Awesome! Thank you so much! – Matthew Apr 7 at 0:33 I wish there was a 'like' button on here :) – Matthew Apr 7 at 0:35 1 The up arrow is the equivalent of "like" :-) – Cyclone Apr 7 at 0:37 it says I need to build up my reputation.

How do I do that? – Matthew Apr 7 at 0:40 And if the answer solves your problem, press the check mark below the up arrow to mark it as the right answer! – Cyclone Apr 7 at 0:41.

This is how to write to a file: php.net/manual/en/function.fopen.php You're better off to use a database tho for sure. To make different links do different things, you can use AJAX as you suggested or you can use GET variables to route functions on the PHP side. The latter is easier but means you will need to reload the page after the user presses the button.

Here's a little demo: click here then at the top of the page in php: if($_GET'clicked'==1){--write to file1---} else if($_GET'clicked'==2){--write to file2---} Hope it helps.

– Cyclone Apr 7 at 0:33 In my experience file_get_contents often causes permissions errors especially when working on a local server. It depends on the specific server setup. Fopen is not that difficult anyway is it?

– cronoklee Apr 7 at 0:37 file_get_contents is just a convenient wrapper for fopen/fread - you'll always get the same permissions errors for the two of them. – ceejayoz Apr 7 at 0:38 I've yet to have permission errors from file_get_contents. If it does give an error, try CHMOD 0777 instead of 0644 which it probably is.

– Cyclone Apr 7 at 0:42 @Cyclone DANGEROUS! You're asking to be hacked. I'm speaking from experience!

– cronoklee Apr 7 at 0:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions