mercredi 27 décembre 2017

Im gonna crazy with checkbox, sql and values

I'm having problems with my new creation. To be realistic, it's my first test with php & SQL.

I read a lot of topics here and didn't find an answer. So, I hope you can help me.

$i = 0;
$inscritos[] = $columna['ArLicencia']; // fill with a query
echo "<input type=\"hidden\" name=\"" . $inscritos[$i] . "\" value=\"0\">"; //Used for not null results
echo "<td><input type=\"checkbox\" name=\"" . $inscritos[$i] . "\" value =" . $columna['ArAsiste']; // get array

if($columna['ArAsiste'] == 1) { //get sql value. checked by default if the value is "1"
    echo " checked";
}

This created a list of checkboxes. Easy, I guess. So, on my action page, I recovered the values of "inscritos" and the value of "value". By default, gets the value of "ArAsiste" from an SQL query and works ok.

But the checkbox is getting me "0" values if checked or null if it isn't checked but didn't get me the lucky "1".

I want to fill two arrays: One with checked licenses and other with non-checked licenses to do a query to update my DB with 1 or 0 values depending on which one I checked before.

$inscritos = $_POST['listado'];

$arrayinscritos = explode(",", $inscritos);
foreach($arrayinscritos as &$valor) {

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


        $licenciasinscritas[] = $valor;

    }
    if($valor2 == 0) {

        $licenciasquenovan[] = $valor;

    }
}

"arraysinscritos" gets the "explode" value of the array "listado" get from the first page by POST, but I don't know what is going on.

Why am I not getting the "1" value when I check and submit the form?




Aucun commentaire:

Enregistrer un commentaire