Removed global variables from database.js

Removed global variables and replaced them with anonymous functions
Added in the line to show the users nsid that is currently stored, tis
got removed somewhere so I'm just adding it back in
Added functionality to insert into the remote database