I need to catch the id of an Event after i have inserted this event. I use the function lastInsertId()
but it doesn't work and I don't know why
I tried many pieces of code I found on the web and also followed videos. I tried exactly the same code I found on the web but does not work .. I'm on MySQL and PHP 7.
$query="INSERT INTO reunion (objet_reunion, heure_reunion, date_reunion, adresse_reunion, lieu_reunion, nbPlace_reunion, duree_reunion, photo_reunion, id_profil) VALUES(:objet, :heure, :date, :adresse, :lieu, :nbPlace, :duree, :photo, :id)";
$prep=$pdo->prepare($query) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$prep->bindValue(':objet', $_POST['objet']);
$prep->bindValue(':heure', $_POST['heure']);
$prep->bindValue(':date', Date("Y-m-d", strtotime($_POST['date'])));
$prep->bindValue(':adresse', $_POST['adresse']);
$prep->bindValue(':lieu', $_POST['lieu']);
$prep->bindValue(':nbPlace', $_POST['nbPlace']);
$prep->bindValue(':duree', $_POST['duree']);
$prep->bindValue(':photo', null, PDO::PARAM_INT) ;
$prep->bindValue(':id', $_POST['id']);
$prep->execute();
$idR=$pdo->lastInsertId();
var_dump($idR);
I expect the output of the id of the last index inserted into the database for updating an index with this id in another champ but i can't find the error in my code.