You forgot to give the $link
from your mysqli_query
to the mysqli_insert_id
.
So the following line:
$pid = mysqli_insert_id($pid);
must be:
$pid = mysqli_insert_id($link);
Check your PHP Error Settings. You should have seen an appropriate Error since you've given an undefined variable to a method expecting an mysqli link.