Hello! I have this bit of code that I’m working on. It gets data from a txt file (just one number) and lets you add to this value and save it back to the text file. The purpose is to add in expense items and keep a running tally of how much has been spent.
[php]<?php
$myFile = “budget.txt”;
$fh = fopen($myFile, ‘r’);
$theData = fread($fh, filesize($myFile));
fclose($fh);
$data = $_POST[‘field1’];
$newtotal = $theData + $data;
$ret = file_put_contents(‘budget.txt’, $newtotal, LOCK_EX);
?>
$<?php echo $theData;?>
[/php]It works except that the page doesn’t update with the new data after you hit the submit button. it only shows up if you manually refresh the page. I would like the value (theData) to update right away… I tried adding header(‘Location: index.php’); at the very start, but that gives me errors (“Warning: Cannot modify header information - headers already sent”).
Thanks for any help!