Replace checbox for radio

Asked

Viewed 82 times

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>';

and then 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 on checkbox Pending it on the table makes the update of that column and also inserts the Completed and if you do it the other way around, the same thing happens and I just want you to do the update on which I put the visa.

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

  • In his query you are informing him to define the Pending and Completed in the State and State fields respectively.

  • In the query of update am. In query query I have this way SELECT centrodb.RegistoManutencao.Id,&#xA; DataRegisto,&#xA; Pedido,&#xA; Outro,&#xA; Descricao,&#xA; Funcionario,&#xA; Imagem,&#xA; Tratamento,Estado1,&#xA; Estado&#xA;&#xA;FROM centrodb.RegistoManutencao LEFT OUTER JOIN centrodb.InfoLuvas&#xA;&#xA;ON centrodb.InfoLuvas.Id = centrodb.RegistoManutencao.Colaborador&#xA;&#xA;WHERE Estado IS NULL;

1 answer

0


In this format you put the checkbox, the $_POST['Id'] comes to PHP as Array, to validate this, put this code snippet to get the variables $pendenteand $concluido.

$registro = $_POST['Id']; 

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

After that, 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 any of the options, it will be recorded in the database as null. I think that solves your problem.

  • Thank you.... solved my problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.