1
In my system has a registration page and a page with a table with the information of registered. In this table there is an edit button that links with an equal form of the registration page.
What should happen:
When clicking the save button, the modified fields should be changed in the record.
What’s going on:
When I try to change the record appears the alert
"successfully saved" and back to the previous page, as it should. But looking at phpMyAdmin, the record remains unchanged
The connection:
<?php
$connection = mysqli_connect("localhost", "root", "", "db_formacao");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Editing form:
<?php
require 'conn.php';
$queryColaboradores = mysqli_query($connection, "SELECT FORMACAO FROM participantes");
$turma = filter_input(INPUT_POST, 'TURMA');
$formacao = filter_input(INPUT_POST, 'FORMACAO');
$colaborador = filter_input(INPUT_POST, 'COLABORADOR');
$Realizado = filter_input(INPUT_POST, 'REALIZADO');
$id = filter_input(INPUT_POST, 'ID');
var_dump($queryColaboradores);
?>
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1 style="
margin-top:100px;">Inscrição</h1>
<p> </p>
<p class="lead"></p>
<ul class="list-unstyled">
<form id="cadastro" method="post" action="banco/updateEdicao.php" style="
text-align: left;
margin-top:50px;">
<fieldset disabled>
<div class="col-lg-12">
<div class="form-group" style="
text-align: left;">
<label for="FORMACAO">Formação: </label>
<input type="text" required class="form-control" id="FORMACAO" name="FORMACAO" value="<?php echo $formacao; ?>">
</div>
</div>
</fieldset>
<fieldset disabled>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="TURMA">Turma: </label>
<input type="text" required class="form-control" id="TURMA" name="TURMA" value="<?php echo $turma; ?>">
</div>
</div>
</fieldset>
<fieldset disabled>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="TURMA">Colaborador: </label>
<input type="text" required class="form-control" id="COLABORADOR" name="COLABORADOR" value="<?php echo $colaborador; ?>">
</div>
</div>
</fieldset>
<fieldset disabled>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="TURMA">ID participante: </label>
<input type="text" required class="form-control" id="PARTICIPANTE" name="PARTICIPANTE" value="<?php echo $id; ?>">
<input type="hidden" name="id" value="<?php echo $id ?>" />
</div>
</div>
</fieldset>
<div class="col-lg-12">
<fieldset disabled>
<div class="form-group">
<label for="previsto">Status</label>
<input type="text" id="PREVISTO" name="PREVISTO" class="form-control" value="Previsto">
</div>
</fieldset>
</div>
<div class="col-lg-12">
<div class="form-group" style="
text-align: left;">
<label for="REALIZADO">Realizado: </label>
<input type="text" required class="form-control" id="REALIZADO" name="REALIZADO" value="Realizado">
</div>
</div>
<div class="">
<button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
</div>
</form>
</ul>
</div>
</div>
</div>
The update:
<?php
$previsto = filter_input(INPUT_POST, 'PREVISTO');
$realizado = filter_input(INPUT_POST, 'REALIZADO');
$id = filter_input(INPUT_POST, 'ID');
$strcon = mysqli_connect('localhost', 'root', '', 'db_formacao') or die('Erro ao conectar ao banco de dados');
$sql = " UPDATE participantes SET REALIZADO = '$realizado' WHERE ID = '$id' ";
mysqli_query($strcon,$sql) or die("Erro ao tentar atualizar registro. " . mysqli_error($strcon));
mysqli_close($strcon);
echo '<script type="text/javascript">
alert("Salvo com Sucesso !");
window.history.go(-1);
</script>';
var_dump($id)
?>
OBS: If I take the WHERE ID = '$id'
all records are updated normally, but with WHERE not.
Have you seen if you’re even getting the ID value on
$id = filter_input(INPUT_POST, 'ID');
? Sometimes the variable$id
is coming nulla.– Leandro Lima
Yes, I gave a var_dump and is getting NULL
– Mariana Bayonetta
By your code, every time you call this page update it will appear
Alterado com sucesso
, I suggest you do a check to see if it is actually being changed in the bank usingmysqli_affected_rows($con);
, I also suggest that you remove thewindow.history.go(-1);
to stay on the page and you can see the error.– Max Rogério
I’m checking if the record is being changed by phpMyAdmin, I already took the window.history.go(-1) to see the error but only print the var_dump.
– Mariana Bayonetta
Disabled does not pass the value to the user, and cannot edit. <fieldset disabled>
– user60252
Yes, not being able to edit is exactly what I want for the fields that are with disabled, which are the fields that were filled in at the time of registration. Only one field is available for editing, which is the Realized.
– Mariana Bayonetta
I have a disabled capo that is getting the value of the participation ID to be edited.
– Mariana Bayonetta
Readonly sends the value to the form and also cannot edit
– user60252
I’ll put an image of my form.
– Mariana Bayonetta
I’ll put the link to another question of mine about another problem in the same form that has to do with what you’re saying. Disabled fields should be receiving a value imported from the bank and are not receiving.
– Mariana Bayonetta
https://answall.com/questions/234124/formul%C3%A1rio-n%C3%A3o-importa-values-do-dados
– Mariana Bayonetta
your form is somewhat curious, disabled with required but cannot edit
– user60252
Because I want this field to exist and be filled in with information that comes from the bank table, but cannot be edited. This is only to show the user the information that he typed in the previous registration, but that he cannot change. The only changeable field is the last, the Realized.
– Mariana Bayonetta
Let’s go continue this discussion in chat.
– Mariana Bayonetta