I have selected the database but for some weird reason it still says that it is not selected.
Connection lines:
$location = \"localhost\"; $user = \"
Make sure your code isn't inserted into classes and stuff, if it's just presented as is, then perhaps 'database' isn't valid, double check your values and try making it an external variable.