does anyone know how to execute deferred MYSQL queries in PHP?

0

I have two related tables (Employees with primary key AI and Role with primary key AI and foreign referenced to the primary Employees) and not to generate inconsistencies in the data or in the autoincrementable key I want to do in the same PHP:

  • inserting information into the Employees table
  • consult the fields in the Employees table and send them to a variable
  • use the consulted variables to populate the Role table

Is there any way to execute one query before another? Would there be any other way to obtain the autoincrementable primary key from the Employees table so that you can directly use the variables in the Role table?

    $query1 = "INSERT INTO Empleados(Nombre_Empleados,Username) 
                    VALUES('$name','$username')";
    mysqli_query($db, $query1);

    $queryidempleados = mysql_query("SELECT idEmpleados FROM Empleados WHERE Nombre_Empleados='$name'");

    $querynombre_empleados = mysql_query("SELECT Nombre_Empleados FROM Empleados WHERE idEmpleados='$queryidempleados'");

    $queryusername = mysql_query("SELECT Username FROM Empleados WHERE idEmpleados='$idempleados'");

    $query2 = "INSERT INTO Rol(idEmpleados,Nombre_Empleados,Username,ConsultaReportes_empleado) 
              VALUES('$queryidempleados','$querynombre_empleados','$queryusername',
              '$employconsult';)";

    mysqli_query($db, $query2);
    
asked by ulises.isc 23.09.2018 в 05:00
source

0 answers