Web Analytics Made Easy -
StatCounter Save variables to file instead of DB? - CodingForum

Announcement

Collapse
No announcement yet.

Save variables to file instead of DB?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Save variables to file instead of DB?

    Hey guys,

    So I'm working on a site that is going to be backed/driven by a database. I'm sort of new to the business and I'm trying to learn it as best as I can in order to create the information system.

    The company is a mortgage broker. I'm finding at this point that the best way to learn and model the system is to actually follow a client through from the front door until the mortgage is paid off.

    At present I'm creating an Application form (the initial form that the potential mortgage client will be filling out).

    It is a multi-page form. I'm using fieldforwarder.php to keep the data between pages.

    There are 5 pages, and it is still growing. I want my client to be able to use my pages in order to give me feedback. However, it seems that he wants to be able save the information in those pages so that he doesn't have to reenter the information if he doesn't need to.

    This is of course understandable. However, at present, I cannot think of another way to allow this action without creating a database, and having all this data inserted into the database. I feel that it will be somewhat of a waste, as I am nowhere near the stage where I can create the actual database schema, and there's a lot of data here to be stored!

    So (finally!) my question is: is there a way to save all the variables in the $_POST array to a file, and then later bring them all back to "life"?

    I'm thinking that at any given time, the user can press a "Save" button, submitting all the form variables to a PHP page, which would then save all the data to a file (perhaps the user will be prompted for a file name). At a later date, the user can be presented with a webpage asking for the file name. This will reload all the variables into a form perhaps, and post them all to the first page of my multi-page form.

    If this is possible, this would greatly increase all of our productivity, and solve my "Save" feature temporarily.

    If anyone has any ideas or comments regarding this, I'd greatly appreciate your input.

    Thanks,
    Sadiq.

  • #2
    well what you could do is have a standard variable that you call $post, and store all postdata in it, like this, its hard to explain so I will comment the code:

    PHP Code:
    $post $_POST// Allows us to change the content of the vars
    // im assuming you have a way of telling who the user is
    if(validUser){
       include(
    "userfile.php");
    }

    foreach(
    $post as $key => $value){
       if(
    trim($value) != ""){
          
    $post[$key] = $user[$key]; // will explain where $user came from.
       
    }

    Which is a rough method for loading the file and making your post array.

    To store information, you can make a php file that will have PHP array:

    PHP Code:
    $output "<"."?php
    \$user = array(
    "
    ;
    foreach(
    $data as $key => $val){ // data would be post data, or your virtual post array
       
    $output .= "'".$key."' => '".$val."',"// adds array lines
    }

    substr_replace($output"", -1); // removes final comma
    $output .= "
    );
    ?"
    .">";

    // ... write into file 
    Its only a very rough draft but it might give you a few ideas.
    PHP Weekly - A PHP Developers Resource
    PHP 5.1.4 and Ruby on Rails web hosting
    Moderator of PHP and Work offers and Requests
    Install Apache/PHP/MySQL
    (by marek_mar) | TinyPlugin Architecture

    Comment


    • #3
      I think I see what you mean.

      Hopefully I'll get some time towards the end of the week or perhaps early next week to sit down and implement it.

      I'll post my solution in case anyone cares to use it down the road some day.

      Thanks for your reply missing-score.

      Sadiq.

      Comment

      Working...
      X