Changing from text file writing to mysql database queries