1
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>";
?>
I now 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 you only enter if you fill in the last row of the table I show in the image.
I want it to insert the rows I fill into the image table and insert all the fields in the row. I’m not making a update
, I really want to make a insert into
which is not working, which error?
– Ricardo Pontual
@Ricardo Punctual, it does not give error and inserts, but only inserts the last line, I intend that it inserts all the lines I fill
– Bruno