I was trying to find out what was wrong with my code. This is the error I'm recieving
"Cannot add or update a child row: a foreign key constraint fails "
This is my code
<?php
$sql = "INSERT INTO stasjon (navn) VALUES ('skogen', 'voksenlia') ";
$resultat = $kobling->query ($sql);
$sql ="SELECT * FROM stasjon WHERE navn = ('skogen')";
$resultat = $kobling->query ($sql);
while ($rad = $resultat->fetch_assoc()) {
$stasjon_id = $rad['stasjon_id'];
}
$sql = "INSERT INTO linjestasjon (linje_nr, stasjon_id) VALUES ('1','$stasjon_id')";
$resultat = $kobling->query ($sql);
if($kobling->query($sql)) {
echo "Spoerringen $sql ble gjennomfoert.";
} else {
echo "Noe gikk galt med spoerringen $sql ($kobling->error).";
?>
Some of it is in Norwegian because That's the language of the database I'm making. I was trying to add values to two different tables (that had stasjon_id as a foreign key) Thanks in advance