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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    57
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question [?] Write dynamic form array to file

    I have a dynamic form and need to be able to write the results to a file:

    FORM:
    Code:
    <form action="index.php" method="post">
    
    <fieldset>  
      <input type="text" name="input[]" size="30" />
      <input type="text" name="input[]" size="30" />
    
    <input type="submit" name="submit" value="Submit" />
    
      </fieldset>
     </form>
    RESULT:
    PHP Code:
    <textarea row="10" cols"10">
    <?php
    foreach ($_POST['input'] as $value
    {  
      
    $value htmlspecialchars($value);

         echo 
    "$value\n";

        }
    ?>
    </textarea>
    WRITE:
    PHP Code:
    // Open file
            
    $handle fopen("path/to/file.txt","w"); 
    // If successful
            
    if ($handle) {
    // Write to file
                
    fwrite($handle$value);
    // Close the file
                
    fclose($handle);

    Ok so if the form had only a single basic input and the result was a simple
    PHP Code:
    <?php echo "$value";?>
    the above write function would work but as its not it doesn't ..I've been Googling for ages now and can't seem to find an answer ..Any ideas ?
    Last edited by buggy; 02-27-2010 at 02:15 PM.
    Newbie at most things ...Hey we all gotta start somewhere right :)

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,546
    Thanks
    8
    Thanked 1,094 Times in 1,085 Posts
    PHP Code:

    <textarea row="10" cols"10"> 
    <?php 

    // Open file 
            
    $handle fopen("path/to/file.txt","w");  
    // If successful 
            
    if ($handle) { 

    foreach (
    $_POST['input'] as $value)  
    {   
      
    $value htmlspecialchars($value); 
            
    // Write to css 
            
    fwrite($handle$value); 

         echo 
    "$value\n"
        } 
    // Close the file 
                
    fclose($handle); 
    }  

    ?> 
    </textarea>

  • Users who have thanked mlseim for this post:

    buggy (02-27-2010)


  •  

    Posting Permissions

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