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 7 of 7
  1. #1
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is this possible?

    http://spiderseatbabies.com/test/

    When I submit the form I want it to add the number to whatever is in the text file.

    So if I put 4 into the form, and 46 was in the text file, it would go to 50 instead of 4.

    index.php
    PHP Code:
    <?php
    $file 
    "m.txt";
    $file_open fopen($file'a+');
    $theData fread($file_openfilesize($file));
    echo 
    $theData;   
     
    ?>
    form.php
    PHP Code:
    <?php
    $file 
    "m.txt";
    $somecontent $_GET['add'];
    if (
    is_writable($file)) {
       if (!
    $handle fopen($file'w+')) {
             echo 
    "Cannot open file ($file)";
             exit;
       }
       if (
    fwrite($handle$somecontent) === FALSE) {
           echo 
    "Cannot write to file ($file)";
           exit;
       }
      
       echo 
    "Added ($somecontent)";
      
       
    fclose($handle);

    } else {
       echo 
    "The file $file is not writable";
    }
    ?>

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    <?php
    $file 
    "m.txt";
    $theData file_get_contents($file);
    $somecontent $_GET['add'] + $theData;
    if (
    is_writable($file)) {
       if (!
    $handle fopen($file'w+')) {
             echo 
    "Cannot open file ($file)";
             exit;
       }
       if (
    fwrite($handle$somecontent) === FALSE) {
           echo 
    "Cannot write to file ($file)";
           exit;
       }
      
       echo 
    "Added ($somecontent)";
      
       
    fclose($handle);

    } else {
       echo 
    "The file $file is not writable";
    }
    ?>
    Won't that work? it was basically what you had...

  • #3
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried that but it doesn't work.

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Is there an error or is the info in the file just wrong?

  • #5
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Instead of adding, it just changes whatever is in the file to whatever you put in the form.

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    <?php
    $file 
    "m.txt";
    $theData file_get_contents($file);
    $somecontent $_GET['add'] + $theData;
    if (
    is_writable($file)) {
       if (!
    $handle fopen($file'w+')) {
             echo 
    "Cannot open file ($file)";
             exit;
       }
       if (
    fwrite($handle$somecontent) === FALSE) {
           echo 
    "Cannot write to file ($file)";
           exit;
       }
      
       echo 
    "Added ($_GET[add])";
      
       
    fclose($handle);

    } else {
       echo 
    "The file $file is not writable";
    }
    echo 
    file_get_contents($file);
    ?>
    works for me =\

  • #7
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh I thought it was the same with "+ $theData" added, didn't see the other stuff.

    Thanks a lot, it works.


  •  

    Posting Permissions

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