1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'PHP & Perl' started by CClark56, Oct 28, 2009.

  1. CClark56

    CClark56 Regular Member

    Joined:
    May 25, 2009
    Messages:
    298
    Likes Received:
    128
    Location:
    Indiana
    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.
     
  2. ukescuba

    ukescuba Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 24, 2008
    Messages:
    994
    Likes Received:
    634
    Occupation:
    Mobile Marketer & QR Code Junkie
    Location:
    San Antonio, TX
    Home Page:
    this may help you...

    Code:
    http://www.tizag.com/phpT/fileappend.php
    you need to open the file to append not to write...

    hth
     
    • Thanks Thanks x 1
  3. CClark56

    CClark56 Regular Member

    Joined:
    May 25, 2009
    Messages:
    298
    Likes Received:
    128
    Location:
    Indiana
    Ah, there we go. Got it working perfectly, thank you so much.