Well, I have these tables with the following structures:
Athletes:
id_atletas
id_identificacao
nome_completo
licenca
Identification:
id_identificacao
nome_pretendido
data_nascimento
The id_identifies as FK in the Athletes table and wanted the athlete to register the id_identifi- cation of the id table in the Athletes table.
I have the following code:
$query_identificacao = "INSERT INTO identificacao (nome_pretendido, data_nascimento) VALUES ('$nome_pretendido', '$data_nascimento')";
$id = mysql_insert_id();
$query_atletas = "INSERT INTO atletas (nome_completo, licenca, id_identificacao) VALUES ('$nome_completo', '$licenca', '$id')";
$id = mysql_insert_id();
mysql_query($query_identificacao) or die(mysql_error());
mysql_query($query_atletas) or die(mysql_error());
But give me the following error:
Can not add or update child row: a foreign key constraint fails (
teste
.atletas
, CONSTRAINTatletas_ibfk_7
FOREIGN KEY (id_identificacao
) REFERENCESidentificacao