I understand using a flat file for a database is not always such a good idea, but for fairly simple things I've had good luck using them. Recently I developed a simple poll for my website using a flatfile to store the users answers. However, I have encountered a problem with this one and can't for the life of me figure out the cause. In my test, I have 9 lines of data in my txt file with each line containing 37 answers separated by commas. The string length of each line is approximately 400 with the total length of the 9 lines of 3515. Now when a new line of data is submitted via the form, it adds the data correctly to a new top line, BUT deletes most, but not all, of the last line in the txt file.
Here is my code and would appreciate some help in making it work.
<?php>
$data = $_SESSION['userfull'].',';
$data = $data .$_POST['B1'].','.$_POST['B2'].','.$_POST['B3'].','.$_POST['B4'].','.$_POST['B5'].','.$_POST['B6'].',';
$data = $data .$_POST['B7'].','.$_POST['B8'].','.$_POST['B9'].','.$_POST['B10'].','.$_POST['B11'].','.$_POST['B12'].',';
$data = $data .$_POST['B13'].','.$_POST['B14'].','.$_POST['B15'].','.$_POST['B16'].','.$_POST['B17'].','.$_POST['B18'].',';
$data = $data .$_POST['B19'].','.$_POST['B20'].','.$_POST['B21'].','.$_POST['B22'].','.$_POST['B23'].','.$_POST['B24'].',';
$data = $data .$_POST['B25'].','.$_POST['B26'].','.$_POST['B27'].','.$_POST['B28'].','.$_POST['B29'].','.$_POST['B30'].',';
$data = $data .$_POST['B31'].','.$_POST['B32'].','.$_POST['B33'].','.$_POST['B34'].','.$_POST['B35'].','.$_POST['age'].',';
$newdata = $data .date("m/d/Y h:i A");
$newdata = nl2br($newdata);
$newdata = stripslashes($newdata);
$file = 'entries.txt';
$olddata=file_get_contents($file);
$newdata = $newdata."\n".$olddata;
$fp = fopen($file,'w+');
$write = fwrite($fp, $newdata, strlen($newdata));
$close = fclose($fp);
?>