insert or update on table \"email\" violates foreign key constraint \"email_contact_id_fkey\"\nDETAIL: Key (contact_id)=(166) is not present in table \"contact\"
<?php
function saveEmail($contactId, $email){
global $pdo;
try {
$stmt = $pdo->prepare("
INSERT INTO emails(contact_id, email)
VALUES (:contact_id, :email)");
$stmt-> bindValue(':contact_id', $contactId);
$stmt-> bindValue(':email', $email);
return $stmt-> execute();
} catch (PDOException $Exception ) {
print_r($Exception);
return false;
}
}
saveEmail(166, 'no@mail.com');