+ Reply to Thread
Results 1 to 9 of 9

Thread: saving php form input to file in cpanel
      
   

  1. #1
    rcarnes1 is offline Sergeant
    Join Date
    Nov 2006
    Posts
    22

    Default saving php form input to file in cpanel

    Looking for coding help to save form input data (an email address) from http://www.leaseown.org/firstpage.php
    to file in cpanel rather than sending it to email address as is now the case.
    Thanks
    Roger

  2. #2
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,061

    Default Re: saving php form input to file in cpanel

    I need to know what kind of file you want to save the data in: .csv. .tab, or .txt. Let's suppose that you wnat to save the form submitted email in a .txt file, with a comma used as separator, and a \r\n as line end. Your script should be something like:


    <?

    // Receiving variable email

    @$email = addslashes($_POST['email']);

    //saving record in a text file

    $file_name = "emailfile.txt"; // emailfile.txt is the name of the file, you can change it to what you want.
    $first_raw = "email\r\n";
    $values = "$email\r\n";
    $is_first_row = false;
    if(!file_exists($file_name))
    {
    $is_first_row = true ;
    }
    if (!$handle = fopen($file_name, 'a+')) {
    die("Cannot open file ($file_name)");
    exit;
    }
    if ($is_first_row)
    {
    if (fwrite($handle, $_first_raw ) === FALSE) {
    die("Cannot write to file ($file_name)");
    exit;
    }
    }
    if (fwrite($handle, $values) === FALSE) {
    die("Cannot write to file ($file_name)");
    exit;
    }
    fclose($handle);
    header("Location: thankyou_page.html");
    ?>
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  3. #3
    rcarnes1 is offline Sergeant
    Join Date
    Nov 2006
    Posts
    22

    Default Re: saving php form input to file in cpanel

    Thanks for the help. The form is in a php page and I do want to use a txt file. Does the above code go in the body of my "action.php" page? Any additional code necessary?
    Roger

  4. #4
    rcarnes1 is offline Sergeant
    Join Date
    Nov 2006
    Posts
    22

    Default Re: saving php form input to file in cpanel

    Naveldesign,
    Everything seems to be working well except an error warning appears on my action1 page. It reads "Warning: Cannot modify header information - headers already sent by (output started at /home/vvisucax/public_html/action1.php: in /home/vvisucax/public_html/action1.php on line 40"
    Any suggestions for fixing this?
    Roger

  5. #5
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,061

    Default Re: saving php form input to file in cpanel

    Yes, it would go in the body of the "action.php". In that case, delete the

    header("Location: thankyou_page.html");

    line. Your action.php is infact your thankyou (or confirmation page).

    This script was a standalone version, which would update the file and then redirect to the thankyou page. Just delete the line and you will be ok.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  6. #6
    rcarnes1 is offline Sergeant
    Join Date
    Nov 2006
    Posts
    22

    Default Re: saving php form input to file in cpanel

    Thanks verymuch. All is working great now!
    Roger

  7. #7
    rcarnes1 is offline Sergeant
    Join Date
    Nov 2006
    Posts
    22

    Default Re: saving php form input to file in cpanel

    Navaldesign

    I now need emaillest.txt in my public_html of leaseown.org to be in a password protected subfolder. I haven't figured out how to do this. Suggestions?

    Roger

  8. #8
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default Re: saving php form input to file in cpanel

    YOU cannot password protect a file. You can password protect the FOLDER that it is in. But keep in mind- this will prevent the script from running as it needs the password to access the folder before it can open the file.

    Why do you need it password protected? Simply change the name of the file given in this thread as an example to a file name only you know. Then make sure to change it in the corresponding parts in the script. You will be the only one who knows it's there.

    Just a thought.

    Andy
    PHP- is a blast!

  9. #9
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,061

    Default Re: saving php form input to file in cpanel

    Andy is correct, you CANNOT password protect a file. However, you can do this: create a script that will allow you and ONLY you to open and view the file contents. Set the file permissions to be 600. This way, only the site owner has permissions to view or edit the file (that's why you need the server side script), whilst the public has no permission to do so.

    Ofcourse, the above requires some coding abilities on your part. If you want to keep things simple, just go the way Andy has suggested.

    However, i do NOT beleive in file storing. I prefer DB storing, and a DB admin interface that allows browsing the info sent, and eventually also exporting the info in Excel, word, csv or xml format for further work. However, this also requires a custom made script, which has a certain cost. If you are interested, contact me
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49