Can you put 2 name to an input?

0

Specifically I have a form which has to fill a table or another depending on the first option chosen, the problem is that the input is the same for both tables and I have to include the 2 name to it, is this possible? , in the test that I did I filled the table but all in white.

This would be my php code:

if($boton == "Guardar"){

    if($rol == 1){

        $pg = "insert into usuarios (usuario, clave, id_rol, correo_usuario) values ('$usuario', '$encriptar', '$rol', '$usuario')";

        $pg1 = "insert into analista (nombre_analista, apellido_analista, correo_analista, telefono_analista, cedula_analista) values ('$nombre', '$apellido', '$correo', '$telefono', '$cedula')";

        if(pg_query($pg) && pg_query($pg1)){

            $_SESSION['guardo'] = $guardo;

        }else{

            echo $error;
        }
    }else if($rol == 2){

        $pg = "insert into usuarios (usuario, clave, id_rol, correo_usuario) values ('$usuario', '$encriptar', '$rol', '$usuario')";

        $pg1 = "insert into instructor (nombre_instructor, apellido_intructor, correo_instructor, telefono_instructor, cedula_instructor) values ('$nombre', '$apellido', '$correo', '$telefono', '$cedula')";

        if(pg_query($pg) && pg_query($pg1)){

            $_SESSION['guardo'] = $guardo;

        }else{

            echo $error;
        }
    }
}

And I have the basic input as follows:

<input type="text" name="nombre_analista, nombre_instructor" class="form-control">

If you can put the 2 name at the same input or there is another way to do what I need

    
asked by Edwin Aquino 25.08.2017 в 03:20
source

2 answers

0

First I would tell you to clean PHP like this, working with a switch and without repeating things:

if ($boton == "Guardar") {
    switch ($rol) {
        case 1:
            $pg1 = "insert into analista (nombre_analista, apellido_analista, correo_analista, telefono_analista, cedula_analista) values ('$nombre', '$apellido', '$correo', '$telefono', '$cedula')";
            break;
        case 2:
            $pg1 = "insert into instructor (nombre_instructor, apellido_intructor, correo_instructor, telefono_instructor, cedula_instructor) values ('$nombre', '$apellido', '$correo', '$telefono', '$cedula')";
            break;
    }
    $pg = "insert into usuarios (usuario, clave, id_rol, correo_usuario) values ('$usuario', '$encriptar', '$rol', '$usuario')";
    if (pg_query($pg) && pg_query($pg1)) {
        $_SESSION['guardo'] = $guardo;
    } else {
        echo $error;
    }
}

Then in the case of html the input should have as name "name" to dry and work it in one way or another depending on the role.

<input type="text" name="nombre" class="form-control">

You can not put two names or you should, the issue is that you manage to use a single name per form.

I hope I have helped!

    
answered by 28.08.2017 в 10:07
0

Optimization suggestion : Use or ignore it as dictated by your heart:

If the role can only take the values 1 and 2, you can simplify your code by entering in the if only that part that changes according to the role:


if($boton == "Guardar"){
    $pg = "insert into usuarios (usuario, clave, id_rol, correo_usuario) values ('$usuario', '$encriptar', '$rol', '$usuario')";

    if($rol == 1) //analista
{       
        $pg1 = "insert into analista (nombre_analista, apellido_analista, correo_analista, telefono_analista, cedula_analista) values ('$nombre', '$apellido', '$correo', '$telefono', '$cedula')";
    }else //instructor ($rol == 2)
{
        $pg1 = "insert into instructor (nombre_instructor, apellido_intructor, correo_instructor, telefono_instructor, cedula_instructor) values ('$nombre', '$apellido', '$correo', '$telefono', '$cedula')";
} 
        if(pg_query($pg) && pg_query($pg1)){

            $_SESSION['guardo'] = $guardo;
        }else{
            echo $error;
        }
}
    
answered by 25.08.2017 в 03:42