guardar múltiples registros con checkbox
Publicado por Ricardo (12 intervenciones) el 11/06/2020 20:28:31
hola a todos espero me ayuden con este problema que me cargo
la cosa es que quiero mandar a guardar desde un modal un registro de empleados el caul se le tomala asistencia con checkbox
la cosa es que al momento de mandarlo me bota un error en el foreach
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Factura_electronica_v14\ajax\nueva_asistencia.php on line 12
aki mi codigos
////////////////////////////////////////////// DISEÑO MODAL//////////////////////////
///////////////////////////////////////////////FUNCION JS /////////////////////////////////////
////////////////////////////////////////// ACCION A REALIZAR/////////////////////////////////////
espero su pronta ayuda !!!!!!!!!!!!!!!!!!!!!1111
la cosa es que quiero mandar a guardar desde un modal un registro de empleados el caul se le tomala asistencia con checkbox
la cosa es que al momento de mandarlo me bota un error en el foreach
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Factura_electronica_v14\ajax\nueva_asistencia.php on line 12
aki mi codigos
////////////////////////////////////////////// DISEÑO MODAL//////////////////////////
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<table class="table">
<tr class="warning">
<th colspan="3" style="text-align:left; font-size:18px;">Fecha:
<input type="text" style="width:200px; height:50px; text-align:center;border: 0;" value="<?php echo strftime("%A,%d %B %Y");?>" readonly ></center>
</th>
<th colspan="3" style="text-align:right;"><a class='btn btn-info'href="#" onclick="agregar_asistencia()">
<i class="glyphicon glyphicon-plus"></i> Agregar Asistencia</a>
</th>
</tr>
<tr class="warning">
<th>Nombre</th>
<th>Apellido</th>
<th><center>Cedula</center></th>
<th><center>Entrada</center></th>
<th><center>Salida</center></th>
<th >
Asistieron todos
<label class="content-input">
<input type="checkbox" id="selectall">
<i></i>
</label>
</th>
</tr>
<?php
while ($row=mysqli_fetch_array($query)){
$id_empleado=$row['id_empleado'];
$id_contrato=$row['id_contrato'];
$nombre=$row['nombre'];
$apellido_paterno=$row['apellido_paterno'];
$cedula=$row['cedula'];
$fecha_contra=$row['fecha_fin'];
$fecha_actual= new DateTime(date('Y-m-d'));
$fecha_final=new DateTime($row['fecha_fin']);
$dias = $fecha_actual->diff($fecha_final)->format('%r%a');
if ($dias>= 1) {
?>
<tr>
<td><?php echo $nombre; ?></td>
<td><?php echo $apellido_paterno; ?></td>
<td><center><?php echo $cedula; ?></center></td>
<td ><center>
<input type="text" style="width:55px; text-align:center;border: 0;" value="8:00" readonly></center>
</td>
<td ><center>
<input type="text" style="width:55px; text-align:center;border: 0;" value="18:00" readonly></center>
</td>
<td >
<label class="content-input">
<input type="checkbox" class="asis" name="asis[]" id="asis" value="<?php echo $id_contrato; ?>">
<i></i>
Asistio</label>
</td>
</tr>
<?php
}else{
?>
<tr>
<td colspan="7" >
<div class="alert alert-danger" role="alert">
<center><strong>¡ NO EXISTEN EMPLEADOS CONTRATADOS !</strong></center>
</div>
</td>
</tr>
<?php
}
}
?>
<tr>
<td colspan=5><span class="pull-right">
<?php
echo paginate($reload, $page, $total_pages, $adjacents);
?></span></td>
</tr>
</table>
///////////////////////////////////////////////FUNCION JS /////////////////////////////////////
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function agregar_asistencia (id)
{
var asis=document.getElementById('asis').value;
$.ajax({
type: "POST",
url: "./ajax/nueva_asistencia.php",
data: "id="+id+"&asis="+asis,
beforeSend: function(objeto){
$("#resultados_empleado").html("Mensaje: Cargando...");
},
success: function(datos){
$("#resultados_empleado").html(datos);
load(1);
}
});
}
////////////////////////////////////////// ACCION A REALIZAR/////////////////////////////////////
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
require_once ("../config/db.php");//Contiene las variables de configuracion para conectar a la base de datos
require_once ("../config/conexion.php");//Contiene funcion que conecta a la base de datos
// escaping, additionally removing everything that could be (html/javascript-) code
$date=date("Y-m-d");
$checkbox=$_POST['asis'];
foreach ($checkbox as $value) {
$eliminar=mysql_query($con,"INSERT INTO asistencia (id_contrato,fecha,asistencia) VALUES ('$value','$date','1')");
if($eliminar){
$messages[] = "Asistiencia completa.";
}else{
$errors[] = "Lo sentimos , ya se tomo asistencia.".mysqli_error($con);
}
}
espero su pronta ayuda !!!!!!!!!!!!!!!!!!!!!1111
Valora esta pregunta
0