Save the checkbox value in the database

0

I need your help ... I have a custom checkbox, where the user clicks and it is "ON" or "OFF" and this value must be recorded in the database and must remain checked or unchecked indicated by the function of this the admin will know whether the employee is ON (at work or not) or OFF. It turns out that it does nothing, writes nothing to the database, and shows nothing in the browser console.

Follow the HTML code

<form id="checkboxs_data" method="POST" accept-charset="utf-8" >
    <input type="checkbox" style="display: none;" id="checkboxs">
    <input type="hidden" name="checkbox_offon" id="checkbox_offon" value="Off"  />
    <input type="hidden" name="nome_offon" value="<?php echo $row_func['nome'];?>" />
    <input type="hidden" name="id_offon" value="<?php echo $row_func['id'];?>" />


<button type="submit" name="actionhCeckbox" id="actionCheckbox" class="btn btn-primary">
    <span class="glyphicon glyphicon-floppy-saved"></span> 
</button></form>

Input is received by jQuery:

<script>
        $(document).ready(function() {
            $('#checkboxs').checkboxpicker({
                onLabel: 'On',
                offLabel: 'Off'
            });

            $('#checkboxs').change(function(){
                if($(this).is(':checked'))
                  {
                   $('#checkbox_offon').val('Off');
                  }
                else
                  {
                   $('#checkbox_offon').val('On');
                  }
            });

            $('#checkboxs_data').on('submit', function(e){

                e.preventDefault();
                var form_data = jQuery(this).serialize();


                jQuery.ajax({
                    url:"checkboxs.php",
                    method:"POST",
                    data:form_data,
                    success:function(html){
                        $('#checkboxs_data')[0].reset();
                        $('#checkboxs').checkboxpicker('On');
                       setTimeout(function(){ window.location.href = ""; }, 1000); 
                    }
                });
             });


        });
    </script>

And then in turn PHP receives the form and writes to the database

<?php 
   $panel_atual = "funcionario";  $data = date("d-m-Y H:s");

$id_offon = $_POST["id_offon"]; 
$nome_offon = $_POST["nome_offon"];
$checkbox_offon = $_POST["checkbox_offon"];

$connect = "UPDATE funcionarios SET offon = '$checkbox_offon' ,  data = 
'$data' WHERE id = '$id_offon'";
$query = mysqli_query($conexao, $connect) ;

if($query)
{
  echo "<script laguange='javascript'> window.alert('done');</script>";
}else{echo "<script laguange='javascript'> window.alert('error'); 
 </script>";}

?>

This is the checkbox button with bootstrap:

    
asked by anonymous 16.06.2018 / 07:17

0 answers