I want to insert a value from my form into my SQL table.
Here's the form:
<form action="index.php?id=" method="GET">
<input id="Trigramme" name="Trigramme" type="text" value="<?php
if (empty($_GET['Trigramme'])):
echo ('');
else:
echo ($_GET['Trigramme']);
endif;
?>">
<input id='idFormation' type="hidden" name="id" value="<?php
if ($formations['ID'] <= $maxIdFormation['Max_ID']):
echo ($formations['ID']+1);
else:
echo ('1');
endif;
?>">
<input type="submit">
</form>
And here's the function I use for the insertion:
function ajouterMembre($infosMembre){
$pdo = getDb();
$requeteAjout = $pdo -> prepare ("INSERT INTO `users` ( `Trigramme`, `Formation_id`) VALUES (':Trigramme', ':Formation_id')");
$requeteAjout -> bindValue(':Trigramme', $infosMembre['Trigramme']);
$requeteAjout -> bindValue(':Formation_id', $infosMembre['id']);
$requeteAjout -> execute();
var_dump($requeteAjout);
var_dump( $infosMembre['id']);
var_dump( $infosMembre['Trigramme']);
return $pdo-> lastInsertId();
}
And lastly, this is the function I use in my HTML:
<?php $idNouveauMembre = ajouterMembre($_GET); ?>
The issue I have is that the SQL returns the values Trigramme = :Trigramme
and id = 0
.
I guess that my bindValue
is not working properly. But when I try to check with:
var_dump( $infosMembre['id']);
var_dump( $infosMembre['Trigramme']);
it returns the correct values I want inserted.