Hi. I'm trying to save a page thats created by a form. Ok so here's how the process folds out (The user enters the information into a web form, then the form sends it to a php page which takes all the info the user entered with $variable = $_POST['form_field']; & uses that to generate an application.

I would like to have all the applications a user enters saved with a file name of their last name ($lastName)

Could somebody tell me how I can do this please?

Thanks, in Advanced

    Check out [man]file_put_contents/man.

    Incidentally, are you sure you don't want to use a relational database for this?

      how can i use that to save the entire page, i've google that hoping to find a tutorial of some sort but it only gives information about saving a string with { echo file_put_contents("test.txt","Hello World. Testing!"); }

      How can i use that to save the entire page?

      And in response to your suggesstion, it's only going to be used to collect about 16 or so forms & save them so it really wouldn't be worth it for me to code it to save it to a database.

        It depends on what you mean by "application", bit you would have to come up with some file format and use that. After all, it is all just text, and text means it can be stored in a string.

          And in response to your suggesstion, it's only going to be used to collect about 16 or so forms & save them so it really wouldn't be worth it for me to code it to save it to a database.

          The thing is, if you do not use a database, you have to come up with a file format (or maybe use an existing one like CSV, or even use XML), and then you still have to write the code to store the data in the given format and then retrieve it for display.

          it's an employment application

          Well yes, you can definitely store that in a text file with a suitable file format. CSV might work for you: [man]fputcsv/man, [man]fgetcsv[/man]. I would still recommend a simple database though.

          If you use a CSV file or a database, you would only need one file (even for the database, if you use SQLite).

          If you want to keep to your current one file per application thing, you use store each field on a separate line and use [man]file/man. It may be a little error prone though, especially since there are multi-line fields in the form.

            I changed the form method to "GET" and then tried doing this to save the file:

            at the top of the page I have:

            <?php
            
               global $lastName;
               ob_start();
               function curPageURL() {
                  $pageURL = 'http';
                  if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
                  $pageURL .= "://";
                  if ($_SERVER["SERVER_PORT"] != "80") {
                     $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
                  } else {
                       $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
                    }
                  return $pageURL;
                }
            ?>

            THEN THE PAGE GOES HERE

            At the bottom of the page I Have:

            <?php
               $content = ob_get_flush();
               $file_to_save = "http://www.ootaclan.org/Brent_Industries/applications/" . $lastName . ".txt";
            
               $return = file_put_contents($file_to_save, $content);
            
               if($return == false){
                  die('Failed to write file!');
               }
            ?>
            

            However it returns this error:

            Warning: file_put_contents(http://www.ootaclan.org/Brent_Industries/applications/File.txt) [function.file-put-contents]: failed to open stream: HTTP wrapper does not support writeable connections. in /home/ootaclan/public_html/Brent_Industries/employee_application.php on line 544
            Failed to write file!

            I've used this method in the past one time, but i've never recieved this error.

              Change this:

              $file_to_save = "http://www.ootaclan.org/Brent_Industries/applications/" . $lastName . ".txt";

              to:

              $file_to_save = $lastName . ".txt";

              or whatever is the appropriate file path. For more information why, read the discussion about allow_url_include.

                one problem if someone has the same name then that will be a bummer.

                <?php
                   $content = ob_get_flush();
                   $file_to_save = $lastName . ".txt"; 
                
                   $return = file_put_contents($file_to_save, $content, "FILE_APPEND");
                
                   if($return == false){
                      die('Failed to write file!');
                   }
                ?>
                
                  Write a Reply...