UGH, that looks super nasty. What if the user enters a space into one of the fields then?
How about using fputcsv instead?
http://php.net/manual/en/function.fputcsv.php
You would then have something like:
...
$fp = fopen("data.txt", 'ab');
fputcsv($fp, array($name, $accno, $dt, $lvisit, $rcall, $com));
fclose($fp);
?>
However, if the user enters a double-quote ", then you are in the same predicament later when reading the data as if you had a space in the data, and a space was a delimiter.
You could use http://ca3.php.net/manual/en/function.addslashes.php on each of the variables you are storing in the file, and http://ca3.php.net/manual/en/function.stripslashes.php on each field when you are reading the data.
Hope that helps!
--
Dan Bernardic
http://dan.bernardic.ca