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


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.


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

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

1 answer


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

$_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