I have a registration form and to enter the data in the database I have to do INSERT in different tables but in the same query. The php code that I have is the following:
<?php
//OBTENGO LOS DATOS DEL FORMULARIO
$usuario = $_POST["usuario"];
$mail = $_POST["mail"];
$password = $_POST["password"];
$passwordEncriptada = password_hash($password, PASSWORD_DEFAULT, array("cost" => 12));
require("datos_conexion.php");
$conexion = mysqli_connect($db_host, $db_user, $db_pass);
if (mysqli_connect_errno()) {
echo "Fallo al conectar con la base de datos";
exit();
}
mysqli_select_db($conexion, $db_nombre) or die("No se encuentra la base de datos");
mysqli_set_charset($conexion, "utf8");
//HAGO LOS INSERT
$registro = "INSERT INTO registro (Reg_Usu, Reg_Mail,
Reg_Pass1) VALUES ('$usuario', '$mail', '$passwordEncriptada'); "
. "INSERT INTO contacto (Con_Usu, Con_Mail) VALUES ('$usuario', '$mail'); "
. "INSERT INTO datos_empresa (Emp_Usu) VALUES ('$usuario'); "
. "INSERT INTO direcciones (Dir_Usu) VALUES ('$usuario'); "
. "INSERT INTO usu_datos (Usu_Usu) VALUES ('$usuario'); ";
$resultados = mysqli_query($conexion, $registro);
if($resultados == false){
echo"La consulta o los datos estan mal!";
echo "<br><br>" . $registro;
}else{
session_start();
$_SESSION["usuario"] = $_POST["usuario"];
header("location:../login/index.php");
}
mysqli_close($conexion);
?>
When executing the code, the La consulta o los datos estan mal!
message I get from validating the results with the mysqli_query($conexion, $registro)
function is printed on the screen. I have seen that the INSERT syntax is correct and the data entered are correct and the funny thing is that when I do it from phpMyAdmin (copying and pasting the same code and using the same values obtained from the variables)
INSERT INTO registro (Reg_Usu, Reg_Mail, Reg_Pass1) VALUES ('usuario', '[email protected]', '$2y$12$1vHoFlWYZlsrO1nVSx1X/eIVwc68dv6MorZxQMO9OMS');
INSERT INTO contacto (Con_Usu, Con_Mail) VALUES ('usuario', '[email protected]');
INSERT INTO datos_empresa (Emp_Usu) VALUES ('usuario');
INSERT INTO direcciones (Dir_Usu) VALUES ('usuario');
INSERT INTO usu_datos (Usu_Usu) VALUES ('$usuario');
I insert everything correctly, but in doing so from the php code no. Would someone know how to find a solution?