7
I’d like your approval.
I need to do 3 INSERT
all at once.
Only I also need to get the last ID of each table, to do the relationship of the tables.
That’s right, do it that way?
if($_GET['operacao'] == 'addPrimeiroCadastro'){
$mysqli->query("INSERT INTO grupo (id_condominio, nome) VALUES ('".$loginUltimoRegistro."','".$_GET['inputPriGrupo']."')");
$ultimoGrupo = $mysqli->insert_id;
$mysqli->query("INSERT INTO unidades (id_condominio, id_grupo, nome) VALUES ('".$loginUltimoRegistro."','".$_GET['inputPriGrupo']."')");
$ultimoUnidade = $mysqli->insert_id;
$mysqli->query("INSERT INTO morador (id_condominio, id_unidade, funcao, nome, cpf, senha) VALUES ('".$loginUltimoRegistro."', '".$ultimoUnidade."', ,'sin', '".$_GET['inputPriNome']."', '".$_GET['inputPriCPF']."', '".$_GET['inputPriSenha']."')");
}
Write data to two tables from a PHP form
– rray
It works more the fact that you did not test whether entered correctly is a problem. It may be that INSERT does not work and it may not get the correct $mysqli->insert_id. If you do not enter $mysqli->insert_id it may be from a previous data entry because you are using a global connection.
– Jhonatan Simões