In my system there is a registration page and a page with a table of the information of the registered ones. This table has an edit button that links to an equal form on the registration page.
What should happen:
When you click the save button, the modified fields should be changed in the registry.
What's happening:
When I try to change the registry, the alert
of "saved successfully" appears and returns to the previous page, as it should. But by looking through 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();
}
?>
Edit 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>
O 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)
?>