I'm trying to get the id of the last inserted row. This is my code:
if($typ == "baby"){
$query ="INSERT INTO duell (user_id, type, namensliste)
VALUES ($id, 1, $duell);";
$result = get_result($query);
$duell_id = $pdo->lastInsertId();
} else if($typ == "hund"){
$query ="INSERT INTO duell (user_id, type, namensliste)
VALUES ($id, 2, $duell);";
$result = get_result($query);
$duell_id = $pdo->lastInsertId();
}
It won't work with lastInsertId() or mysql_insert_id() as it always returns 0 even tough I execute it directly after the Insert and the query works properly. The id of the table is auto increment and primary. What am I doing wrong? Thank you for your help :)