Replace checbox for radio

0

I have this code where I create two columns of type="checkbox" :

$tabela1 .= '<td> <input type="checkbox" name= "Id[]" value="'.$rows_cursos['Id'].'"></td>';
$tabela1 .= '<td> <input type="checkbox" name= "Id[]" value="'.$rows_cursos['Id'].'"></td>';

Then I do this update to the database table where I only assign this value to input type="checbox" :

$registro = $_POST['Id'];
$tratamento = $_POST['Tratamento'];
$imagem = $_POST['Imagem'];

foreach($registro as $value) { 
    $conn->query("UPDATE RegistoManutencao SET Estado1 = 'Pendente', Estado = 'Concluido', Tratamento = '$tratamento', Imagem = '$imagem' WHERE Id=" . $value); 
}

But when I put the visa in the% Pending it in the table it does checkbox of that column and also inserts the Completed and if it does the same happens the same and I want you to only do the update in the one I put the visa to.

I put an example image where I select the pendant but in the table it inserts the pending and completed and should only insert what I select:

    
asked by anonymous 16.02.2018 / 10:55

1 answer

0

In this format you have placed the checkboxes, $_POST['Id'] comes to PHP as Array , to validate this, put this code snippet to get the $pendente and $concluido variables.

$registro = $_POST['Id']; 

$arr = array_flip($registro); 
$pendente = isset($arr['Pendente']) ? 'Pendente' : null; 
$concluido = isset($arr['Concluido']) ? 'Concluido' : null; 

After this, change the query line:

 $conn->query("UPDATE RegistoManutencao SET Estado1 = '$pendente', Estado = '$concluido', Tratamento = '$tratamento', Imagem = '$imagem' WHERE Id=" . $value);

So when the user does not check in any of the options, it will be written to the database as null . I think that solves your problem.

    
16.02.2018 / 21:49