tags:

views:

23

answers:

2

Code works fine, except for the fact that there is a problem here:

 //Log Events
function logEvent($newinput) {
    if ($newinput !== NULL) {
        // Add a timestamp to the start of the $message
        $newinput = date("Y/m/d H:i:s").': '.$newinput;
        $fp = fopen('log.txt', 'w');
        fwrite($fp, $newinput."\n");
        fclose($fp);
    }
}
//Problem writing these two lines to log.txt?
 //The bad, the two lines below are not on the log.txt
logEvent('Selection'.$selections[$selection]);
logEvent('Change' . $change. 'cents.');

//This line is written to a text file (log.txt), okay that's good.
logEvent('Input' .  $newinput);
+1  A: 

i think you're not appending to the file, you're rewriting it. try fopen with 'a' instead of 'w'.

ufk
Sweetness, thanks, just wondering do people around here ever sleep...
Newb
It could be anytime of day, and you will get a response faster than lightening, that's awesome.
Newb
Again, thanks ufk.
Newb
glad i could help :)
ufk
A: 

You need to use the append modifier when opening the file, you've gone

fopen('log.txt', 'w');

this means that every time you call that function, the log file is getting blown out and recreated, if you instead used

fopen('log.txt', 'a');

then your new log entries will append to the file instead.

You could also look into keeping the file open for later inserts too, but there may be issues with multiple updates in other requests.

philjohn