I have a .txt based database setup, and when I do fscanf to find a uname, then fseek to go right after it, then fwrite it fwrite's over the \n, and over the top of the rest of the unames... I cant figgure out how to stop this overwriting in the file. My script is

<html>
<body>
<?php

if(!($_SERVER['HTTP_REFERER']==='http://dburg-php.bizhat.com/teacher-consol.php'))
exit('You can not access this page. Please log into your console and edit the database that way.');

switch($_POST[f_type]) {

case school:



echo "school right
";
if(!($s=fopen('sdb.txt','r+')))
exit('Unable to open schoolwork database file.');
fscanf($s,$_COOKIE['uname']);
fseek($s,-3,SEEK_CUR);
fwrite($s,"|$_POST[month]-$_POST[day]");
fwrite($s,"|$_POST[topic]");
fwrite($s,"|$_POST[subject]|\n");
echo(ord(fgetc($s)));




/* while(!(ord(fgetc($s))==='254'))
{
fseek($s,-1,SEEK_CUR);
fwrite($s,'');
}
*/ break;
case home:
echo 'home right';
if(!($h=fopen('hdb.txt','r+')))
exit('Unable to open homework database file.');
break;
default:
echo 'This page was not retrieved correctly. Please re-log into your console and try again.';
break;
}


?>
</body>
</html>

It's been commented out in a few spots and others aren't completed

but it's the basic function under the school case. Any ideas? ty in advance