I've got a problem in my PHP code whith an SQL statement.
I want to get back the ID of my Indice where my name = 'myname'. Here is my code :
<?php
include 'Connection.php';
try {
$db = new PDO("$server:host=$host;dbname=$base", $user, $passwd);
//Statement = INSERT INTO indice
$stmtInd = $db->prepare("INSERT INTO indice(ID, Name, IDFormation)
VALUES (:ID, :Name, :IDFormation)");
$stmtInd->bindParam(':ID', $id);
$stmtInd->bindParam(':Name', $name);
$stmtInd->bindParam(':IDFormation', $idformation);
//Statement = INSERT INTO note
$stmtNote = $db->prepare("INSERT INTO note(ID, Valeur, Valeurtext, IDIndice)
VALUES (:ID, :Valeur, :Valeurtext, :IDIndice)");
$stmtNote->bindParam(':ID', $ID);
$stmtNote->bindParam(':Valeur', $valeur);
$stmtNote->bindParam(':Valeurtext', $valeurtext);
$stmtNote->bindParam(':IDIndice', $IDindice);
$noteIdindice = $db->prepare("SELECT ID FROM indice WHERE Name = :Name");
$noteIdindice->bindParam(':Name', $name);
$noteIdindice->execute();
$resultat = $noteIdindice->fetch(\PDO::FETCH_ASSOC);
var_dump($resultat);
//Indice 1
$name = "Equilibre theorie / pratique";
$idformation = "1";
$stmtInd->execute();
$valeur = $_POST["indice1"];
$valeurtext = "";
$IDindice = $resultat['ID'];
$stmtNote->execute();
echo "Success";
}
catch (PDOException $e) {
die("Impossible de se connecter a la source de donnees...");
}
?>
There is other Indice but you dont need it cuz its the same as "//Indice 1".
Everything works and i have no failure. But my query give me a wrong return. It returns me "0" instead of the ID i want.
Do you guys know why ?