[Need Help] Saving input text into a text file

Discussion in 'PHP' started by C a s p e r, Oct 1, 2008.

  1. #1
    So I attempted to solve this on my own and this is as much as I got

    <!-- save query //-->
    <?php
    
    if($_POST['q']){
    $file_name = "something.txt";
    
    $file_open = fopen("something.txt","a+");
    fwrite($file_open, $_POST['q']);
    fclose($file_open);
    }
    ?>
    <!-- end save query //-->
    
    <form class="url_form" method="post" action="/index.php">
    <div id="surfcontainer">
    					<input type="text" id="surfbox" name="q" value="{DEFAULT_URL}" />
    					<input type="image" value="" src="{THEME_DIR}/imgs/surf_button.gif" style="float: left; border: 0px;" />
    <!-- save query //-->
    <?php
    $datalines = file ("something.txt");
    
    foreach ($datalines as $zz) {
    echo $zz; }
    
    ?>
    <!-- end save query //-->
    </form>
    </div>
    
    PHP:
    Using this I get undefined function for q and no info is written to the something file anyone have an idea how to make it to the inputted data is saved into the text file on separate lines.
     
    C a s p e r, Oct 1, 2008 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Whats the error message?

    use this to write on seperate line
    <?php
    
    if ($_POST['q'] != '') {
    $file_name = "something.txt";
    $file_open = fopen("something.txt","a+");
    fwrite($file_open, "{$_POST['q']}\r\n");
    fclose($file_open);
    }
    ?>
    PHP:
     
    ads2help, Oct 1, 2008 IP
  3. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Buddy, i have tested the script and its working fine... have u CHMOD your something.txt(where data should be saved) to 666?
     
    mehdi, Oct 1, 2008 IP
  4. C a s p e r

    C a s p e r Peon

    Messages:
    313
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I get
    can see it running here


    I have it at 777


    It is saving some of the urls but it doesnt save any that I put in I have tried 777 and 666

    You can try and look at the searched page to see if it saved it
     
    C a s p e r, Oct 1, 2008 IP
  5. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try this adding on top of your PHP page:
    
    error_reporting (E_ALL ^ E_NOTICE);
    
    PHP:
     
    mehdi, Oct 1, 2008 IP
  6. C a s p e r

    C a s p e r Peon

    Messages:
    313
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks I went ahead and removed it as its not working correctly.
     
    C a s p e r, Oct 1, 2008 IP