0
I show this data with the select
and after the user query can edit three fields: Image, Treatment and Status. The State camp is doing the update
correct in table, but the fields input type="file"
and input type="text"
is only correct if you edit one line at a time. This is the code:
$result_cursos = "SELECT centrodb.RegistoManutencao.Id,
DataRegisto,
Pedido,
Outro,
Descricao,
Funcionario,
Imagem,
Tratamento,
Estado
FROM centrodb.RegistoManutencao LEFT OUTER JOIN centrodb.InfoLuvas
ON centrodb.InfoLuvas.Id = centrodb.RegistoManutencao.Colaborador
WHERE Estado IS NULL OR Estado <> 'Concluído';";
$resultado_cursos = mysqli_query($conn, $result_cursos);
$tabela1 .= '<div style="float: center" table align="center">';
$tabela1 .= '<table border="5">';
$tabela1 .= '<tr>';
$tabela1 .='<thead>';
$tabela1 .= '<tr>';
$tabela1 .= '<th>Nº Registo</th>';
$tabela1 .= '<th>Data</th>';
$tabela1 .= '<th>Pedido</th>';
$tabela1 .= '<th>Outro Local</th>';
$tabela1 .= '<th>Descrição</th>';
$tabela1 .= '<th>Colaborador</th>';
$tabela1 .= '<th>Imagem</th>';
$tabela1 .= '<th>Tratamento</th>';
$tabela1 .= '<th>Estado</th>';
$tabela1 .= '</tr>';
$tabela1 .='</thead>';
$tabela1 .='<tbody>';
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela1 .= '<tr>';
$tabela1 .= '<td>'.$rows_cursos['Id'].'</td>';
$tabela1 .= '<td>'.$rows_cursos['DataRegisto'].'</td>';
$tabela1 .= '<td>'.$rows_cursos['Pedido'].'</td>';
$tabela1 .= '<td>'.$rows_cursos['Outro'].'</td>';
$tabela1 .= '<td>'.$rows_cursos['Descricao'].'</td>';
$tabela1 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela1 .= '<td> <input type="file" name= "Imagem" id= "Imagem" value="'.$rows_cursos['Imagem'].'"></td>';
$tabela1 .= '<td> <input type="text" name= "Tratamento" id= "Tratamento" value="'.$rows_cursos['Tratamento'].'"></td>';
$tabela1 .= '<td> <input type="radio" name= "Id['.$rows_cursos['Id'].']" value="Pendente"> Pendente <input type="radio" name= "Id['.$rows_cursos['Id'].']" value="Concluido">Concluido</td>';
$tabela1 .= '</tr>';
}
$tabela1 .= '</tr>';
$tabela1 .='</tbody>';
$tabela1 .= '</table>';
$tabela1 .= '</div>';
echo "<form method='POST' action=''>";
echo $tabela1;
echo "<input type='submit' name='registar' value='Registo'>";
echo "</form>";
?>
Where later in the update I create the variables this way and do update
:
<?php
if(isset($_POST['registar']))
{
$registro = $_POST['Id'];
$tratamento = $_POST['Tratamento'];
$imagem = $_POST['Imagem'];
foreach($registro as $Id => $estado) {
$conn->query("UPDATE RegistoManutencao SET Estado='".$estado."', Imagem = '$imagem', Tratamento = '$tratamento' WHERE Id='".$Id."'");
}
}
?>
I want that when editing more than one line, it does the update
is correct in the lines I am editing and only makes it correct in the status field. In the field image and treatment is only correct if you do the update
one line at a time.
Could you better contextualize the question? Describing the scenario to be applied to the solution? If you can describe it I believe it will be easier for the community to help you
– Felipe
The problem is that when I’m doing the
update
The column image and treatment will always fetch the last line both in white and with data, because it does not know theid
of the line I’m making theupdate
– user104114
@Junior You can create buttons in each row of the table that make the update run unique (for each row you click) (this would be for updating image and processing). Or you can try sending the entire table by renaming the fields to an array. Make sure the way you are doing you are sending all the lihas of the table. Give a print_r($_POST) and check if there is an element array in the post. Later I can make an example for you
– Felipe