-2
I’m still a beginner in mysql and php but after some studies I’m trying to create a system and in case I’m having trouble with FOREING KEY, I have two tables a 'tb_students' and 'tb_notes' but I’m trying to make a relationship with 'id_student' and 'id_note' but when I do the Insert via a form the information in 'tb_note' does not arrive while the information of 'tb_students' is going perfectly.
Code I created the tb_notas
CREATE TABLE tb_notas (
id_notas INT(5) NOT NULL AUTO_INCREMENT PRIMARY key,
portugues VARCHAR(45) NOT NULL,
matematica VARCHAR(45) NOT NULL,
geografia VARCHAR(45) NOT NULL,
ciencia VARCHAR(45) NOT NULL,
id_alunos(5)NOT null,
FOREIGN KEY(id_alunos) REFERENCES tb_alunos(id_alunos)
);
follows the code of the Insert
$sql = "INSERT INTO alunos(id_alunos, nome, sexo, idade)
VALUES ('$nome','$sexo','$idade')";
$query= mysqli_query($connect,$sql);
if($query){
$sql2 = "INSERT INTO notas(portugues, matematica, geografia, ciencia) VALUES('$portugues','$matematica','$geografia','$ciencia')";
$result= mysqli_query($connect, $sql2);
header('Location: ../lista_alunos.php');
}else{
echo "ERROR".mysqli_error($connect);
?>
I ended up undoing the relationship to test and it worked, but when I put the relationship the information won’t go
Please edit the question to limit it to a specific problem with sufficient detail to identify an appropriate answer.
–
Can I add the php code together? where you do the
insert via um formulário
?– Danizavtz
"does not arrive while the information of 'tb_students' is going perfectly" needs more details, not mentioned if the error, what the message, does not have the php code, so it is difficult to help.. but note that first you need to insert the student so you can use your id in notes, see the order that does this in your code and for more help put the code
– Ricardo Pontual