Again I have found the answer to my own question after no response from anyone else.
Apparently its very easy to solve the problem. I looked at the code of all the prepared statements and found there to be a $con variable defined as the db_connect prepared statement.
so in order for this to work I did this
$con= db_connect(); $last_id = mysqli_insert_id($con);
Basically this defines the variable $con and allows mysqli_insert_id to use it