I'm using MVC php model to build my web site but I get an issue trying to insert current userId
from one table to another table (foreign key).
I'm using MySQL last version on ubuntu.
You can see my table below where I want to set the foreign key.
My code:
private function insert() {
$sql = "INSERT INTO ".self::TABLE_NAME." (last_name_par_enfant, first_name_par_enfant, date_naissance_par_enfant, sexeEnfant, medecin_traitant_par, scolariseEnfantPar, commentaire, date_inserted, idfamily)
VALUES (
:last_name_par_enfant,
:first_name_par_enfant,
:date_naissance_par_enfant,
:sexeEnfant,
:medecin_traitant_par,
:scolariseEnfantPar,
:commentaire,
NOW()
:idfamily)";
$pdoStatement = Database::getPDO()->prepare($sql);
$pdoStatement->bindValue(':last_name_par_enfant', $this->last_name_par_enfant, PDO::PARAM_STR);
$pdoStatement->bindValue(':first_name_par_enfant', $this->first_name_par_enfant, PDO::PARAM_STR);
$pdoStatement->bindValue(':date_naissance_par_enfant', $this->date_naissance_par_enfant, PDO::PARAM_STR);
$pdoStatement->bindValue(':sexeEnfant', $this->sexeEnfant, PDO::PARAM_STR);
$pdoStatement->bindValue(':medecin_traitant_par', $this->medecin_traitant_par, PDO::PARAM_STR);
$pdoStatement->bindValue(':scolariseEnfantPar', $this->scolariseEnfantPar, PDO::PARAM_STR);
$pdoStatement->bindValue(':commentaire', $this->commentaire, PDO::PARAM_STR);
$pdoStatement->bindValue(':idfamily', $idfamily, PDO::PARAM_INT);
$affectedRows = $pdoStatement->execute();
return $affectedRows;
}
Comments
Post a Comment