Answer the question
In order to leave comments, you need to log in
Error with foreign key?
I have an error
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\"
Answer the question
In order to leave comments, you need to log in
In development of Lander's answer
<?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, '[email protected]');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question