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.
$result = fclose($open) ; if($result) { echo "thank you "; } else { echo "error with file closing"; } or something like that should do it.
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:
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.