You're closing the connection with
mysqli_close($link);
- it's called if the form has been submitted, but it's outside the check to see if the submit was successful. You just need to put it immediately after the msysqli_stmt_close($stmt);
line