PHP - Colocar celda de checkbox en base de datos mysql

 
Vista:

Colocar celda de checkbox en base de datos mysql

Publicado por blooming (2 intervenciones) el 10/12/2019 20:47:13
Tengo una base de datos de +600 becarios en la cual tengo que insertar dos columnas nuevas, una donde indique si el becario esta dado de baja o continua activo y la otra en la que tengo marcar quienes realizaron su evaluación mensual, ya tengo ambos checkbox vinculados a la base de datos, mi problema radica en que no se como asignar un checkbox por cada becario. Este es el codigo index.html que utilicé

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset ="UFT-8">
<title> Document </title>
</head>
<body>
<form method="POST" action="validar.php">
<input type="checkbox" name="checkbox[0]" value="Octubre"> Octubre <br>
<input type="checkbox" name="checkbox[1]" value="Noviembre"> Noviembre <br>
<input type="checkbox" name="checkbox[2]" value="Diciembre"> Diciembre <br>
<input type="checkbox" name="checkbox[3]" value="Enero"> Enero <br>
<input type="checkbox" name="checkbox[4]" value="Febrero"> Febrero <br>
<input type="checkbox" name="checkbox[5]" value="Marzo"> Marzo <br>
<input type="checkbox" name="checkbox[6]" value="Abril"> Abril <br>
<input type="checkbox" name="checkbox[7]" value="Mayo"> Mayo <br>
<input type="checkbox" name="checkbox[8]" value="Junio"> Junio <br>
<input type="checkbox" name="checkbox[9]" value="Julio"> Julio <br>
<input type="checkbox" name="checkbox[10]" value="Agosto"> Agosto <br>
<input type="checkbox" name="checkbox[11]" value="Septiembre"> Septiembre
<br>
<input type="submit">
</form>
</body>
</html>
y esta es la validación
 
<?php
$link=mysqli_connect("localhost", "Ana", "********");
if($link){
mysqli_select_db($link, "becarios");
}
$checkbox=$_POST['checkbox'];
foreach ($checkbox as $llave =>$valor) {
$ficha2="INSERT INTO tabla3 SET nombre='$valor'";
$ejecutar_insertar_ficha2=mysqli_query ($link, $ficha2);
 
}
 
?>
Espero haberme explicado bien y que me puedan ayudar. Saludos cordiales
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder