How to take the value of two selects with the same name and that php receives them?

2

How could I take the value of two selects for PHP to receive them to be able to make a foreach and insert it in the database? since what is required is for a user to have two roles at the same time.

that is to say that in my detail table you can insert at the same time the id of the user and the role which would be in the following way:

detalle_id_usuario: 1
detalle_id_usuario: 1
detalle_id_rol: 1 (Administrador)
detalle_id_rol: 5 (coordinador)

Something like that is how it should be inserted at the same time but I do not know in what way ... I would appreciate the collaboration.

HTML

<select name="rol_usuario">
<option value="1">Administrador</option>
<option value="2">usuario</option>
</select>

<select name="rol_usuario">
<option value="3">jefe de area</option>
<option value="4">tecnico</option>
<option value="5">coordinador</option>
</select>
    
asked by JDavid 06.04.2017 в 23:21
source

1 answer

2

only treat the variable in php as a array , since it will travel to the server in the following way.

[POST]
$_POST => rol_usuario { "valor_campo1", "valor_campo2"  }

for what you can use a:

count($_POST['rol_usuario']) // retornará 2 en este ejemplo
    
answered by 07.04.2017 в 00:30