1
I have this code:
<?php
$j=0;
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela1 .= '<tr>';
$tabela1 .= '<td> <input type="text" size="45" name= "NomeUtente[]" id= "NomeUtente" value="'.$rows_cursos['nome'].'"></td>';
$tabela1 .= '<td> <input type="text" size="1" name= "Quarto[]" id= "Quarto" value="'.$rows_cursos['Quarto'].'"></td>';
$tabela1 .= '<td> <input type="datetime" name= "DataRegisto[]" id= "DataRegisto" value="'. date("Y-m-d H:i:s") .'"></td>';
$tabela1 .= '<td> <input type="checkbox" name= "Miccao['.$j.']"> Realizado <input type="text" name= "Tipo1[]" id= "Tipo1" size="30" ></td>';
$tabela1 .= '<td> <input type="checkbox" name= "Dejeccao['.$j.']"> Realizado <input type="text" name= "Tipo[]" id= "Tipo" size="30" ></td>';
$tabela1 .= '<td> <select name="Colaborador[]" id="Colaborador">
<option value="xxxxxxxxxxxx">xxxxxxxxxxxxx</option>
</select></td>';
$tabela1 .= '</tr>';
$j++;
}
$tabela1 .='</tbody>';
$tabela1 .= '</table>';
$tabela1 .= '</div>';
echo "<form method='POST' action=''>";
echo $tabela1;
echo "<input type='submit' name='registar' value='Registo'>";
echo "</form>";
echo "</br>";
echo "</br>";
?>
To insert I have the following:
<?php
if(isset($_POST['registar']))
{
$NomeUtente = $_POST['NomeUtente'];
for ($i=0;$i<count($_POST["NomeUtente"]);$i++) {
$utente = $_POST['NomeUtente'][$i];
$quarto = $_POST['Quarto'][$i];
$data = $_POST['DataRegisto'][$i];
$miccao = $_POST['Miccao'][$i];
$tipo1 = $_POST['Tipo1'][$i];
$dejeccao = $_POST['Dejeccao'][$i];
$tipo = $_POST['Tipo'][$i];
$colaborador = $_POST['Colaborador'][$i];
$miccao = $miccao == "on" ? "Realizado" : "";
$dejeccao = $dejeccao == "on" ? "Realizado" : "";
$sql = "INSERT INTO registoMiDe (NomeUtente, Quarto, DataRegisto, Miccao, Tipo1, Dejeccao, Tipo, Colaborador) VALUES ('$utente', '$quarto', '$data', '$hora', '$miccao', '$tipo1', '$dejeccao', '$tipo', '$colaborador')";
$res = mysqli_query($conn,$sql);
}
}
?>
Now you should only insert into the table the rows where I select one or two checkboxes, but so you are inserting all the rows when I log into the database table. It was working fine, while not showing the value in the Datalog field
This is the change that I have made and is no longer working:
$tabela1 .= '<td> <input type="datetime-local" name= "DataRegisto[]" id= "DataRegisto" ></td>';
for
$tabela1 .= '<td> <input type="datetime" name= "DataRegisto[]" id= "DataRegisto" value="'. date("Y-m-d H:i:s") .'"></td>';
truth... It was simpler than I proposed. kkkk
– Andrei Coelho