Hi,

I want to use fopen and fwrite to write a html file for user send info and this info will be stored in a txt file.

<?php
$address = "address.data";

function displayAdress($address) {
$file = fopen("$address", "w");
fwrite($file);
fclose($file);
}
displayAddress($address);
?>

However, the info submitted by html form could not be recorded in address.data file.
What's wrong with the code?

Thanks

gogo

    from the manual
    fwrite
    (PHP 3, PHP 4 )

    fwrite -- Binary-safe file write
    Description

    int fwrite (int fp, string string [, int length])

    I wouldn't thing that the way you are calling fwrite would work, since there are 2 required parameters.

    you're basically just opening and closing a file, since you provide no data to write to the file.

    check
    http://www.php.net/manual/en/function.fwrite.php
    for more info

      What's wrong with the code?

      In addition to the other things not already mentioned, you must test the return value of fopen() to see if it was able to perform the action requested, and not just blindly write to the file handle.

        Thanks for all of your kind help.

        But, I think I might ask the wrong question. I saw a php book which said that the return value of fwrite was integer.

        But, what I want to do is that:
        1) The user can input text info from a html page such as name, tel, add and email.
        2) When the user submits the form, the info will be sent and store in a txt file of the server. If there is no such file, it will be created automatically by fopen.

        Was I wrong to use fwrite? If so, which one should I use in this case?

        Thanks a lot.

        gogo

          Write a Reply...