I'm getting quite angry over this, I don't know how can this simple situation be so complicated and not work.
Basically:
$lastInsertId = mysqli_insert_id($query);
echo $lastInsertId;
What is $query
? You have to pass the mysqli link as parameter ($link = mysqli_connect(...)
). Maybe your $query is the result of mysqli_query or something else.
mixed mysqli::mysqli_insert_id ( mysqli $link )
Manual: http://php.net/mysqli_insert_id