Added isfile() function and fixed inserting database query