0
My code when registering a new user:
$sql1 = "INSERT INTO usuario (login, senha_hash, nome, email, direito_deAcesso)
VALUES ('{$usuario}', '{$senha_hash}', '{$nome}', '{$email}', '{$direito_deAcesso}')";
$query1 = mysqli_query($conexao, $sql);
After a new user is registered, I have to associate him with a partner. In summary, a partner may have one or more hitched users and a user may only be hitched to a single partner.
So, after the user is registered and the query is executed, I run another:
$sql2 = "INSERT INTO parceiro_has_usuario (idUsuario, idParceiro)
SELECT usuario.idusuario FROM usuario
WHERE login = '{$usuario}'";
idUsuario and idParceiro are two Foreign key.
What I want to include in sql2 to include in the table parteiro_has_usuario (which contains the two fks) is the name of the partner that is in the table partner.
I tried something like that, but it didn’t work:
$sql2 = "INSERT INTO parceiro_has_usuario (idUsuario, idParceiro)
SELECT usuario.idusuario FROM usuario
WHERE login = '{$usuario}',
SELECT parceiro.nome FROM parceiro WHERE nome = '{$parceiro}'";
Could you help me? By the way, I don’t know if I’m doing it the right way to add the values in the table that contains the two fk.
makes use of indices along with the logical operator AND
– user45474