if fclose() function succedd then echo something.. how to do it?

Discussion in 'PHP' started by kakkalo, Jan 29, 2009.

  1. #1
    lets say it open a file and write successfully but then how can i make it to write some thing if it success to close the flie.

    <?php
    if (isset($_POST['submit'])) {
    $filename = "name.txt"; // Where the “name” is name of file it will create if file doesnt exist, and will write data on it.
    $open = fopen($filename, "a") or die("Couldn't open file for writing!");
    $name = $_POST['name'] ;
    $age = $_POST['age'];
    $hidden = $_POST['hidden'];
    fwrite($open, "Name:\t$name\r") or die("Couldn't write values to file!");
    fwrite($open, "Age:\t$age\r");
    fwrite($open, "Hidden:\t$hidden\r\r");
    fclose($open);
    }
    ?>
    PHP:
    for here after fclose($open); it will echo something like "thank your for submitting"

    is there anyway to do it. thank you.
     
    kakkalo, Jan 29, 2009 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    $result = fclose($open) ;
    if($result) { echo "thank you "; }
    else { echo "error with file closing"; }

    or something like that should do it.
     
    shallowink, Jan 29, 2009 IP
  3. kakkalo

    kakkalo Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nope its not working. is there any other way that you can think of....
     
    kakkalo, Jan 29, 2009 IP
  4. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #4
    Nope. You must have done something different. I just tested that code, it works like a charm.
    And if you actually want help, you are going to need to post more than "it didn't work". Stuff like what did the script output? It's in an IF/ELSE statement so it has to print something or there was an error. Remember all I have to work with is what you tell me or show me.
    
    <?php
    $filename = "name.txt"; // Where the “name” is name of file it will create if file doesnt exist, and will write data on it.
    $open = fopen($filename, "a") or die("Couldn't open file for writing!");
    
    $result = fclose($open) ;
    if($result) { echo "thank you "; }
    else { echo "error with file closing"; }
    ?>
    
    PHP:
     
    shallowink, Jan 30, 2009 IP
  5. kakkalo

    kakkalo Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hey thank you man, i figured out what i was doing wrong.
    i was putting both
    fclose($open) ;
    $result = fclose($open) ;

    that is why it was showing me error. thank you very much for helping me with this casue this is really new stuff to me.
     
    kakkalo, Jan 30, 2009 IP
  6. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #6
    that's cool, good luck with it.
     
    shallowink, Jan 30, 2009 IP