-1
I’ve been looking at dozens of topics, but I still can’t find a solution.
I created a form that shows the database table data and when the data is changed I need to update the table row.
this is the code I have but does not update in the table:
<form action="" method="post">
<label>Insira a data:</label>
<input name="data" type="date" placeholder="Type Here">
<br>
<br>
<input type="submit" value="Enter">
</form>
<?php
if(isset($_POST['data']))
{
$servername = "xxx.xxx.x.xx";
$username = "xxxxx";
$password = "xxxxxxxxx";
$dbname = "xxxxxxxx";
$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8');
$inicio = mysqli_real_escape_string($conn, $_POST['data']);
$sql = "SELECT `regOratorio`.`DataEntrada`,
`regOratorio`.`Utente`,
`regOratorio`.`Estado`,
`regOratorio`.`Observacao`,
`InfoLuvas`.`Funcionario`
FROM `centrodb`.`regOratorio` LEFT OUTER JOIN `centrodb`.`InfoLuvas`
ON `centrodb`.`InfoLuvas`.`Id` = `centrodb`.`regOratorio`.`Colaborador` WHERE DataEntrada = '$inicio'";
$result=mysqli_query($conn, $sql);
if (!$result) {
echo 'There are no results for your search';
} else {
// result to output the table
echo '<form name="customer_details" action="" method="POST" onsubmit="return alguma_funcao()">';
}
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo "<fieldset>";
echo "<table cellspacing='10'>";
echo "<tr>";
echo "<td>";
echo "<label>Data</label>";
echo "<input type='date' id='DataEntrada' name='DataEntrada' value='".$row['DataEntrada']."'";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</fieldset>";
echo "<fieldset>";
echo "<table cellspacing='10'>";
echo "<tr>";
echo "<td>";
echo "<label>Utente</label>";
echo "<input id='' type='text' value='".$row['Utente']."'";
echo "<label>Estado</label>";
echo "<input type='radio' id='Estado' name='Estado' value='Presente' " . ( ($row['Estado']=='Presente') ? 'checked' : '' ) ."> Presente";
echo "<input type='radio' id='Estado' name='Estado' value='Ausente' " . ( ($row['Estado']=='Ausente') ? 'checked' : '' ) ."> Ausente";
echo "<label>Observacão</label>";
echo "<input type='text' id='Observacao' name='Observacao' value='".$row['Observacao']."'";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</fieldset>";
echo "<fieldset>";
echo "<table cellspacing='10'>";
echo "<tr>";
echo "<td>";
echo "<label>Colaborador</label>";
echo "<input type='text' id='Funcionario' name='Funcionario' value='".$row['Funcionario']."'";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</fieldset>";
echo "<input name='atualizar' type='submit' id='atualizar' value='Atualizar'>";
}
echo "</form>";
}// end submitted
?>
<?php
if(isset($_POST['atualizar']))
{
$data = $_POST['DataEntrada'];
$estado = $_POST['Estado'];
$observacao = $_POST['Observacao'];
$estadofinal = $_POST['EstadoFinal'];
echo $sql1 = "UPDATE regOratorio SET Estado = '$estado', Observacao = '$observacao', EstadoFinal = '$estadofinal' WHERE DataEntrada = '$data'";
if ($conn->query($sql1) === TRUE);
//Count total number of rows
$rowCount = $query->num_rows;
}
$conn->close();
?>
When I update it shows this data inside the if(isset($_POST['atualizar']))
Have you checked if you’re entering the
if(isset($_POST['atualizar']))
?– Sam
How can I verify, with the
echo
?– user104114
Yes, you can put an echo inside the if, if it shows nothing it is because it is not entering, so it will not update.
– Sam
I put in question the result of when I update with the
echo
and I think it goes into theif(isset($_POST['atualizar']))
, but does not update data within the table– user104114
remove the echo... echo is for printing on the screen
– Sam
I removed the
echo
but does not update the table row in the same– user104114
Updates on which line?
– Sam
I explained wrong above, does not update anything in the table in any row
– user104114
The problem may be in the WHERE that is not finding the date. What is the type of the field
DataEntrada
on the table?– Sam
It’s the primary key
– user104114
But it’s like date, datetime, varchar?
– Sam
It’s like date, that’s the problem?
– user104114
removed the echo from here huh ? echo $sql1 ...
– Julio Henrique
yes I withdrew....
– user104114
Are you sure there is the date '2018-02-05' in the table?
– Sam
Yes there is...is the only line I have on the table
– user104114
You do not have to run the $sql1 query before if?
– Sam
Do not update the table row in the same way
– user104114