[PHP/HELP] Submit, save and go to.

CClark56

Regular Member
Joined
May 25, 2009
Messages
299
Reaction score
128
Okay, so I'm working on one of my sites and I'm wanting to save a text field to a text file on my server. I found this code:

PHP:
<?php
$content = $_POST['content'];
$file = "file.txt";
$Saved_File = fopen($file, 'w');
fwrite($Saved_File, $content);
fclose($Saved_File);
?>


And then modded it to my liking.

But noticed that it doesn't save the previous content, it only overwrites it. So I figured I'd try and fix it like this:



PHP:
<?php
header("Location: gotourl.com");
$content = $_POST['content'];
$file = "file.txt";
$old_content = file_get_contents($file);
fwrite($file, $content."\n".$old_content);
fclose($file);
?>


Now it isn't even saving, what am I doing wrong exactly?

Also, I'm not very good at PHP, I miss a lot of functions and generally just suck at it, so it might be a stupid problem in the script.

Thanks to anyone who replies.
 
this may help you...

Code:
http://www.tizag.com/phpT/fileappend.php

you need to open the file to append not to write...

hth
 
Ah, there we go. Got it working perfectly, thank you so much.
 
Back
Top