mysqli_insert_id不工作

I am trying to get last autoincrement id from INSERT/UPDATE query, i am trying this way, but its not working, it just echo id=0 every time.

PHP

require_once('conn.php'); 
$temp = 'temp';

$query = "INSERT INTO temp (temp) VALUES('$temp')";
$result = mysqli_query($conn, $query) or trigger_error(mysqli_error($conn), E_USER_ERROR);

$id = mysqli_insert_id($conn);
echo 'id = '.$id;

Please see and suggest any possible way to do this.

Try changing the query to.

INSERT INTO `temp` (`temp`) VALUES('$temp')