Your connection has been closed, after execution of first SELECT Statement, it means connection closed to early:
$conn->close();
You need to use close()
after your all queries or re build connection. ist one is the better option.
You are getting user input $_REQUEST['key']
, it means your query is open for SQL injection, this will help you to understand how can you prevent your code with SQL injection: How can I prevent SQL injection in PHP?