I have selected the database but for some weird reason it still says that it is not selected.
Connection lines:
$location = \"localhost\";
$user = \"         
        
Another reason why this error pops up is because the username and password which you are using to access the database may not have appropriate read/write persmissions. Especially on a shared hosting server, you will need to assign the appropriate username to the corresponding database. I recently had this problem, I had created a new database and forgot to assign persmissions for my existing username.