Mysqli_insert_id Not working
I'm trying to get the last autoincrement id from an INSERT / UPDATE query, I try this way, but it doesn't work, it just echoes 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 take a look and suggest any possible way to do this.
+3
source to share