This is usually closing the connection then trying to use it, but if the above is the complete code, then you aren't connecting to the database and that could be it. This bit from your original code.
<?php
$link = mysqli_connect("localhost", "root", "", "homedb");
// Check connection
if($link...