Insert Data With PHP after having related tables in sql

-1

I'm doing a data entry and then create a table in which I have two types of user (administrator and client), but when I relate it to the table in which all the registered users are going to be stored, I try to register a new user and does not register me, how could I solve this with php? I mean the part where having the relationship in the BD is not registering me,

<code><?php
//Incluimos La Conexion
include ("conexion.php");

//Guardamos Valores En Variables
$nameuno = $_POST["nombreuno"];
$namedos = $_POST["nombredos"];
$lastuno = $_POST["apellidouno"];
$lastdos = $_POST["apellidodos"];
$tipoDoc = $_POST["Documento"];
$NroDoc = $_POST["Identificacion"];
$pass = $_POST["pass"];
$inst = $_POST["IU"];
$cargo = $_POST["cargo"];
$laboratorio = $_POST["laboratorio"];
$bloque = $_POST["bloque"];
$NroLabo = $_POST["NroLaboratorio"];

//Insertamos Los Datos Del Usuario En La BD
$insertar = "INSERT INTO 'usuarios'( 'NombreUno', 'NombreDos', 'ApellidoUno', 'ApellidoDos', 'TipoDocumento', 'NroDocumento', 'Contrasena', 'Institucion', 'Cargo', 'Laboratorio', 'Bloque', 'NroLaboratorio') VALUES ('$nameuno', '$namedos', '$lastuno', '$lastdos', '$tipoDoc', '$NroDoc', '$pass', '$inst', '$cargo', '$laboratorio', '$bloque', '$NroLabo')";

//Verificacion De Documento
$verificar_documento = mysqli_query($conexion, "SELECT * FROM usuarios WHERE NroDocumento = '$NroDoc'");
if (mysqli_num_rows($verificar_documento) > 0){
    echo '<script>alert("El Usuario Ya Esta Registrado");
    window.history.go(-1);
    </script>';
    exit;
}

//Ejecutamos La Consulta
$resultado = mysqli_query($conexion, $insertar);
if (!$resultado){
    echo '<script>alert("Error Al Registrar");
    window.history.go(-1);</script>';
    exit;
}else {
    echo '<script>alert("Usuario Registrado Exitosamente");
    window.history.go(-1);</script>';
    exit;
}

//Cerrar Sesion
mysqli_close($conexion);

?></code>
    
asked by The Universe Android 25.12.2018 в 22:22
source

1 answer

1

I understand that what you mention is that basically the php code that you have put does not work well and users are not registered.

I'm not sure but I think in this line there may be an error with the apostrophes:

$insertar = "INSERT INTO 'usuarios'( 'NombreUno', 'NombreDos', 
            'ApellidoUno', 'ApellidoDos', 'TipoDocumento', 'NroDocumento', 
            'Contrasena', 'Institucion', 'Cargo', 'Laboratorio', 'Bloque', 
            'NroLaboratorio') VALUES ('$nameuno', '$namedos', '$lastuno', 
            '$lastdos', '$tipoDoc', '$NroDoc', '$pass', '$inst', '$cargo', 
            '$laboratorio', '$bloque', '$NroLabo')";

Change to this one and try:

$insertar = "INSERT INTO usuarios( NombreUno, NombreDos, ApellidoUno, 
            ApellidoDos, TipoDocumento, NroDocumento, Contrasena, 
            Institucion, Cargo, Laboratorio, Bloque, NroLaboratorio) VALUES 
            ('$nameuno', '$namedos', '$lastuno', '$lastdos', '$tipoDoc', 
             '$NroDoc', '$pass', '$inst', '$cargo', '$laboratorio', 
             '$bloque', '$NroLabo')";
    
answered by 26.12.2018 в 00:00