Change value 0 to 1 in sql using checkbox in php

0

I have a form with a checkbox and fields of an sql query like this:

checkbox - registry data

The checkbox must be checked or not depending on the value it has in the database. It is a tinyint field that I have put a conditional on loading the page that is 1, mark it, and if it is zero, do not do it.

The user will mark the checkboxes that he / she thinks appropriate and when sending the form, he / she generates a query that updates the table and all the records of the table in the field related to the checkbox.

This is the code of the form:

$inscritos[]=$columna['ArLicencia'];
            echo "<input type=\"hidden\" name=\"".$inscritos[$i]."\" value=\"0\">"; // incluido para evitar valores null
            echo "<td><input type=\"checkbox\" name=\"".$inscritos[$i]."\" value =".$columna['ArAsiste'];


            if ($columna['ArAsiste'] == 1){
                echo " checked";
            }

By sending the form, on the action page, I extracted a string with the licenses (ArLicencia) and separated it.

On the other hand, I extracted a string with the values of the checkboxes of this type:

As the name, the license and as a value, the value that is marked. In theory it should be 0 for unmarked, and 1 for marking.

$inscritos = $_POST['listado'];

$arrayinscritos = explode(",",$inscritos);

foreach ($arrayinscritos as &$valor){

$valor2 = $_POST[$valor];
if ($valor2 == 1){

    $licenciasinscritas[]=$valor;

}
if ($valor2 == 0){

    $licenciasquenovan[]=$valor;


}
}

With this, what I do is create two strings, one with the marked licenses and others with the unmarked ones. Then, I create the query to execute to update the ArAsiste field as 1 or as 0.

The problem is that when I check the box, it does not return a 1.

For example, I have two licenses, the frames, and when printing what you return to me, it is this:

(83209 - 0) (92742 - 0)

And if I do not check them, it gives me back the same.

What is the problem?

    
asked by Joaquin Requejo 27.12.2017 в 20:26
source

0 answers