Error al Validar checkbox, PHP JS AJAX HTML
Publicado por Lukaz (1 intervención) el 31/07/2019 22:09:04
Buenas compañeros tengo un problema al hacer click en un checkbox, tengo guardado en la base de datos como 29 registros y al momento de hacer click solo funciona con el 1er registro en mi base de datos esta personalizado con 0 y 1, 0 seria cuando no esta checkeado y 1 cuando esta checkeado el problema tb es que solo esta reconociendo el primer ID por mas que haga click en los demas ID, aqui el codigo.
codigo php y html
aqui el escript con el ajax
y aqui el UPDATE
codigo php y html
1
2
3
4
5
6
7
8
9
10
11
12
<form enctype="multipart/form-data" id="fupForm" autocomplete="off" name="myForm" method="post" action="">
<input type="hidden" id="idlv" name="idlv" class="check" value="<?php echo $idlv; ?>">
<label><?php echo $idlv; ?>. - <input type="checkbox" id="venta" name="venta[]" class="check" <?php if ($venta==1) { ?> checked <?php } ?> value="<?php echo $idlv; ?>" />venta</label>
<label><input type="checkbox" id="confiteria" name="confiteria[]" class="check" <?php if ($confiteria==1) { ?> checked <?php } ?> value="<?php echo $idlv; ?>" />Confiteria</label>
<input type="hidden" name="usuario_id" value="<?php echo $usuario_id; ?>">
</form>
aqui el escript con el ajax
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
$(document).ready(function(e){
$("#fupForm").on('submit', function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'pruebachekin.php',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(msg){
$('.statusMsg').html('');
if(msg == 'ok'){
$('#fupForm')[0].reset();
window.location.reload();
}else{
console.log(msg);
}
}
});
});
$(".check").change(function(){
$("#fupForm").submit();
});
});
y aqui el UPDATE
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
$venta=0;
$confiteria=0;
/*echo $idlv;*/
if(!empty($_REQUEST['idlv']))
{
if(!empty($_POST['venta'])){
$venta = ($_POST['venta']);
if ($venta='on'){$venta=1;}
}
if(!empty($_POST['confiteria'])){
$confiteria = ($_POST['confiteria']);
if ($confiteria='on'){$confiteria=1;}
}
$idlv = $_REQUEST['idlv'];
$queryUpd = mysqli_query($conection, "UPDATE lista_ventas SET venta = $venta, confiteria = $confiteria WHERE idlv = $idlv ");
mysqli_close($conection);
if($queryUpd){
$code = '1';
$msg = "Venta Actualizada.";
}else{
$code = '2';
$msg = "Error.";
}
$arrData = array ('cod' => $code, 'msg' => $msg, 'venta' => $venta, 'confiteria' => $confiteria, 'idlv' => $idlv );
echo json_encode($arrData,JSON_UNESCAPED_UNICODE);
exit;
}
Valora esta pregunta


0