You have to reconnect to get the info.
$sql = "SELECT id FROM table";
$result = @mysql_query($sql,$connection) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
}
That should work, as long as you replace table with the table name and id with whatever you named the field for your auto-incrementing field.