Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/04/2013, 14:27
Avatar de Briss
Briss
 
Fecha de Ingreso: junio-2011
Mensajes: 1.293
Antigüedad: 12 años, 9 meses
Puntos: 12
Insertar array check box

Hola estoy tratando de insertar varios registros de acuerdo al numero de check box seleccionados pero solo he conseguido insertar un solo registro
este es mi form:

<form .....>
<table >
<td>
D&iacute;a:
<td width="196" height="31" valign="middle">
<input type="checkbox" name="dia[]" value="1"/>L
<input type="checkbox" name="dia[]" value="2"/>M
<input type="checkbox" name="dia[]" value="3"/>Mi
<input type="checkbox" name="dia[]" value="4" />J
<input type="checkbox" name="dia[]" value="5"/>V
<input type="checkbox" name="dia[]" value="6" />S
<input type="checkbox" name="dia[]" value="7"/>D
</td>
</tr>



</tr>


<tr >
<td >Hora Inicio:</td>
<td><input name="hinicio[]" id="hinicio" value="" size="26"/></td>
</tr>
<tr>
<td ><div align="left"><font size="2">Hora Fin:</font></div></td>
<td ><input name="hfin[]" id="hfin" value="" size="26"/></td>
</tr>

y el codigo

Código PHP:
foreach($_POST["dia"] as $key => $value){
  
$insertSQL sprintf("INSERT INTO horario (dia, hinicio, hfin) VALUES (%s,%s,%s)",    
                        
GetSQLValueString($_POST['dia'][$key], "text"),
                    
                       
GetSQLValueString($_POST['hinicio'][$key], "text"),
                       
GetSQLValueString($_POST['hfin'][$key], "text")); 


Se inserta solo una vez por ejemplo si marco lunes y miercoles
hinicio=8
horafin:12
en mi Bd solo se inserta 1,8,12
y no 1,8,12 y 3,8,12

Desde ya Gracias