examining fwrite in database write function
changed format so variables are declared at the beginning of functions