I have this code:
<?php
$result_cursos = "SELECT nome,
Quarto
FROM centrodb.utentes
WHERE descricaovalencia = 'LAR' AND nome <> 'CLASSE' AND ativo = '1' ORDER BY nome ASC;";
$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 WIDTH="200" text-align="center">Utente</th>';
$tabela1 .= '<th WIDTH="30" text-align="center">Quarto</th>';
$tabela1 .= '<th WIDTH="80" text-align="center">Data Registo</th>';
$tabela1 .= '<th WIDTH="80" text-align="center">Micção</th>';
$tabela1 .= '<th WIDTH="80" text-align="center">Dejecção</th>';
$tabela1 .= '<th WIDTH="80" text-align="center">Colaborador</th>';
$tabela1 .= '</tr>';
$tabela1 .='</thead>';
$tabela1 .='<tbody>';
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela1 .= '<tr>';
$tabela1 .= '<td WIDTH="200" align="center"> <input type="text" name= "NomeUtente" id= "NomeUtente" value="'.$rows_cursos['nome'].'"></td>';
$tabela1 .= '<td WIDTH="30" align="center"> <input type="text" style="WIDTH="30" align="center" name= "Quarto" id= "Quarto" value="'.$rows_cursos['Quarto'].'"></td>';
$tabela1 .= '<td WIDTH="80" align="center"> <input type="date" name= "DataRegisto" value="echo date("Y-m-d")"</td>';
$tabela1 .= '<td WIDTH="80" align="center"> <input type="checkbox" name= "Miccao" value="Realizado"></td>';
$tabela1 .= '<td WIDTH="80" align="center"> <input type="checkbox" name= "Dejeccao" value="Realizado"></td>';
$tabela1 .= '<td WIDTH="80" align="center"> <select name="Colaborador" id="Colaborador">
<option></option>
<option value="1">teste</option>
$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>";
echo "</br>";
echo "</br>";
?>
Now I use this code to insert into the database table:
<?php
if(isset($_POST['registar']))
{
$utente = $_POST['NomeUtente'];
$quarto = $_POST['Quarto'];
$data = $_POST['DataRegisto'];
$miccao = $_POST['Miccao'];
$dejeccao = $_POST['Dejeccao'];
$colaborador = $_POST['Colaborador'];
$sql = "INSERT INTO registoMiDe (NomeUtente, Quarto, DataRegisto, Miccao, Dejeccao, Colaborador) VALUES ('$utente', '$quarto', '$data', '$miccao', '$dejeccao', '$colaborador' )";
if ($conn->query($sql) === TRUE);
//Count total number of rows
$rowCount = $query->num_rows;
}
?>
The problem is that it only inserts if you fill in the last line of the table that shows in the image.
I intend it to insert the rows that I fill in the table of the image and insert the fields all of the line. I'm not doing update
, I really want to insert into