Hi, I am working with this code I found in this forum awhile back. Now, it works as I want but, it overwrites the previous data in the txt file. I need to keep adding the data to the file without overwriting it. Example: http://www.videoboob.com/holly/index.php Code I am using: <?php $saving = $_REQUEST['saving']; if ($saving == 1){ $data = $_POST['data']; $file = "data.txt"; $fp = fopen($file, "w") 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!"; } ?> <form name="form1" method="post" action="index2.php?saving=1"> <textarea name="data" cols="100" rows="10"> Vehicle #: RO #: Date: Tech Assigned: Warranty: Current Status: Comments: --------------------------------------------- </textarea> <br> <input type="submit" value="Save"> </form> <p> <a href="http://www.videoboob.com/holly/data.txt"><b>VIEW<b></a> Can someone help me with this code, please. Thanks, Joe
Change fopen to use append rather than write mode. So change it from: fopen($file, "w") to: fopen($file, "a")
Am working on a project here similar to this one. But instead of saving a text field, i would like to save input fields. Right now i can only save the username part but password i can't, can u guys help me on what im doing wrong. EDIT: also if there is a way to separate the data with a: , - or /. This is the code im using, from the PHP part to the form : <?php $saving = $_REQUEST['saving']; if ($saving == 1){ $data = $_POST['USERNAME']; $file = "data.txt"; $fp = fopen($file, "a") or die("Couldn't open $file for login!"); fwrite($fp, $data) or die("Couldn't open new page!"); fclose($fp); echo "Proceed to newly open page."; } ?> PHP: [ICODE] <form onsubmit="window.open ('step2.php')" action="index.php?saving=1" method="post"> Username:<input name="USERNAME" tabindex="1" maxlength="20" value="" type="text"> Password:<input name="PASSWORD" tabindex="2" maxlength="20" value="" type="password"> <input tabindex="3" title="Sign In" onclick="imgClick('IEfix1',this.value)" value="Save" src="home_files/sign-in.gif" alt="[Sign In]" type="image"> <input name="Reset" class="button2" tabindex="4" title="Reset" onclick="this.form.reset();return false" src="home_files/reset.gif" alt="[Reset]" type="image"> </form>[/ICODE]
Check this article to store form data in microsoft word or in text file. Here's the link Storing form data in notepad or in microsoft word Hope it will work for you!
First of all, thank you for somehow keeping a 7 year old thread visible - provides a solution I have been looking for for several days straight (eyeballs burning)..Applied and changed the code and it works greaat. What I bump into is that, rather than 1 textarea, I am trying to save a whole set of fields from a form like this. Can I? If so, how can I put fiels seperators in the output saved to the text file?Any help is welcome!Maurice
found the answer to the mutliple field save in a related thread - but not the solution for the field seperator issue
hi i found this to google an i never connect to data base, the database called notes.txt, any who can help, please, <html> <head><title> My guestbook</title> <body> <h1>Welcome to my Guestbook</h1> <h2>Please write me a little note below</h2> <form action="" method="POST"> <input type="text" name="user" placeholder="Name" /> <br /> <textarea cols="40" rows="5" name="note" placeholder="Comments" wrap="virtual"></textarea> <br /> <input type="submit" name="submit" value="submit" /> </form> <?php if (isset($_POST['submit'])){ $user = $_POST['user']; $note = $_POST['note']; if(!empty($user) && !empty($note)) { $msg = $user . ' : ' . $note; //will open a file $fp = fopen("notes.txt", "r") or die ("can't open file"); //will write to file fwrite($fp, $msg."\n"); fclose($fp); } } ?> <h2>The entries so far:</h2> <?php $file = fopen("notes.txt", "r") or exit("unable to open file!"); //output a line of the file until the end is reached while(!feof($file)) { //will return each line with a break echo fgets($file). '<br />'; } fclose($file); ?> </body> </html>
I only saw this post now. But if you wanna write into file, only need to change r to w (write) or w+ (read/write) $fp = fopen("notes.txt", "r") or die ("can't open file"); PHP: to $fp = fopen("notes.txt", "w") or die ("can't open file"); PHP: Maybe this can be usefull for someone.
y you can add any seperator like '<br/>' or any other character to seperate the fields. You append instead of writing to file if you are not trying to overwrite the file's content.