Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to write to a file on submit button click?

    Hi all,
    I'm having 4 textboxes. The values of which needs to be written to a file when i click the submit button. How do i do that? Please help.

    the code is below:
    Code:
    <font size=3 > Detailed Results </font>
    <Input type="textbox" name="Det_Results" size="60"/>
    <br><br>
    <font size=3 > Test Summary </font>&nbsp;&nbsp;&nbsp;&nbsp;
    <Input type="textbox" name="Test_sum" size="60"/>
    <br><br>
    <font size=3 > Ref FFT Location </font>
    <Input type="textbox" name="Ref_fft" size="60"/>
    <br><br>
    <font size=3 > Build Path </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <Input type="textbox" name="bui_path" size="60"/>
    <br><br><br>
    <INPUT type="submit" value="Run Automation" onclick="" />
    Thanks,
    Ramki.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    First you need to have a <form> line that specifies the PHP script to run
    when the form is submitted:

    <form action="myprocessingscript.php" method="post">
    .
    .
    .
    <input type="submit" name="submit" value="Save Data">
    </form>


    Then you have some decisions to make ...

    In the PHP script called "myprocessingscript.php", it will open a text
    file and append your data ... but append it on one line with a comma
    separating the values, or what? Tell us what your file should look like?

    I mention comma separation because it could be a .csv file that you
    import into Excel?

    Not enough information to answer your question.

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Look into (google, php manual, etc) the functions fopen() and fwrite().

  • #4
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    First you need to have a <form> line that specifies the PHP script to run
    when the form is submitted:

    <form action="myprocessingscript.php" method="post">
    .
    .
    .
    <input type="submit" name="submit" value="Save Data">
    </form>


    Then you have some decisions to make ...

    In the PHP script called "myprocessingscript.php", it will open a text
    file and append your data ... but append it on one line with a comma
    separating the values, or what? Tell us what your file should look like?

    I mention comma separation because it could be a .csv file that you
    import into Excel?

    Not enough information to answer your question.
    Thanks. I've a form element set to POST. My main objective is to write these textbox data to a file and parallely a WINDOWS command window should open and execute a perl file. Thats all.

    The text file which the code has to write will be as below.

    Code:
    Input_File	C:\Program Files\Apache Group\Apache2\htdocs\Automation_streams.txtt
    Detailed_Results	C:\Audio_Regress\files\Results_MPEG_48kHz_7405.txt	
    Test_Summary	C:\Audio_Regress\files\Test_summary_MPEG_48kHz_7405.txt	
    Reference_FFT_Location	C:\Audio_Regress\FFT\Ref\MPEG	
    Sync_Delay	0	
    Path	cd /home/raghav/Phase2pt0_Blr/Brutus
    where the text boxes will replace the values of Detailed Results, Test Summary,Reference_FFT_Location and Path as shown above.
    Any help?

    Thanks,
    Ramki.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Here's the PHP script to write to a file, but not sure about the Windows/Perl thing ...

    PHP Code:
    <?php

    // Get form variables using POST method
    $Det_Results=stripslashes($_POST['Det_Results']);
    $Test_sum=stripslashes($_POST['Test_sum']);
    $Ref_fft=stripslashes($_POST['Ref_fft']);
    $bui_path=stripslashes($_POST['bui_path']);

    // Open and write file
    $myFile="datafile.txt";
    $fh fopen($myFile'w+') or die("can't open file");
    fwrite($fh"Input_File    C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Automation_streams.txt
    Detailed_Results $Det_Results
    Test_Summary $Test_sum    
    Reference_FFT_Location    $Ref_fft
    Sync_Delay    0
    Path    $bui_path"
    );
    fclose($fh); 

    echo 
    "file written\n";
    ?>
    You also don't need this part in your form:
    <INPUT type="submit" value="Run Automation" onclick="" />


  •  

    Posting Permissions

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