Little PHP help?

Discussion in 'PHP' started by Lipgut, Jan 3, 2010.

  1. #1
    Hello. I am having this little problem , here is my code;
    <?php
    header("Location: msgchanger3.html");
    $ourFileName = "test.txt";
    $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
    $handle = fopen( "test.txt", "a");
    $value = $_POST['111'];
    $y = '1500';
    $x = $value - $y; 
    fwrite($handle, $x);
    fclose($handle);
    exit;
    ?>
    PHP:
    I need it to subtract from the "$y" and save the subtracted value so next time you subtract an input it subtracts from the last calculation. I don't know it that makes sense but if you understands please tell me how to , or an approach I should think about on how to do this. Thanks!


    By The way. I have only been coding PHP for a week or so , so I understand the basics and I am just starting to get more complicated , so if you could keep it as noob friendly as possible , thank you :)
     
    Lipgut, Jan 3, 2010 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    I would use a database table to hold the temporary value
     
    javaongsan, Jan 3, 2010 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <?php
    // Get the value submitted via form
    $value = $_POST['111'];
    // Load file content of text.txt value
    $con = file_get_contents('test.txt');
    // Subtract posted value from saved value
    $new_value = $con - $value;
    // Save new value to text.txt file
    file_put_contents('test.txt', $new_value);
    
    // Redirect
    header('Location: msgchanger3.html');
    exit();
    
    PHP:
    Something like that?
     
    JAY6390, Jan 3, 2010 IP