What's happening:
I have a system that, when I finish filling out the form and save, does not save the changes appearing a alert
of "saved without changes" and returning to the previous page.
What should happen:
When you try to save the form, the Saved script should appear successfully and return to the previous page.
As I do not master this language, I'm not finding out where the logic is responsible for recognizing that a field was changed and saving. I believe the error is in the form, since there is nothing wrong with the bank or the connection. Since I can not put the whole system here, I'll put some parts that I believe may be responsible for the error:
Find ID of what you want to change
<?php
// Busca valores no banco de dados para preenchimento do formulario para alterar
$id = $_GET['id'];
$sql = (" SELECT * FROM re WHERE id = '{$id}'");
$query=mysql_query($sql);
while ($campo = mysql_fetch_assoc($query)) {
?>
part of the form
<div class="container">
<form method="post" action="../std/update.php" enctype="multipart/form-data" name="re" class="formulario">
<div class="container container-divisor">
<h4>Descrição Re</h4>
<div class="row">
<input type="hidden" name="idnovo" id="idnovo" value="<?=$campo['id'];?>">
<input type="hidden" name="dataedicao" id="dataedicao" value="<?php echo date('d/m/Y'); ?>">
<div class="col-md-4">
<label for="datacriacao">Data</label>
<input type="text" class="form-control" name="datacriacao" id="dataCriacao" value="<?=$campo['datacriacao'];?>"127>
</div>
</div>
</form>
In the page responsible for updating the database, the texts in js:
<?php
if(mysql_affected_rows() > 0){
?>
<script type="text/javascript">
alert("Salvo com Sucesso !");
window.history.go(-1);
</script>
<?php
}
else{
?>
<script type="text/javascript">
alert("Salvo sem Modificações !");
window.history.go(-1);
</script>
<?php
}
mysql_close($conexao);
?>
The update page
<?php
include ("conecta.php");
//coletando dados do formulario
$id = $_POST["idnovo"];
$dataedicao = $_POST["dataedicao"];
$datacriacao = $_POST["datacriacao"];
$statusgeral = $_POST["statusgeral"];
$criadopor = $_POST["criadopor"];
// Inserir dados no banco
$itens = $_POST['meti'];
//$_POST['meti'] as $itens
if (!empty($itens)){
$itens = implode(',', $_POST['meti']);
}
$up= mysql_query("UPDATE retex SET dataedicao = '$dataedicao', datacriacao = '$datacriacao', statusgeral = '$statusgeral', criadopor = '$criadopor' WHERE id = '$id' ");
?>
<?php
if(mysql_affected_rows() > 0){
?>
<script type="text/javascript">
alert("Salvo com Sucesso !");
window.history.go(-1);
</script>
<?php
}
else{
?>
<script type="text/javascript">
alert("Salvo sem Modificações !");
window.history.go(-1);
</script>
<?php
}
mysql_close($conexao);
?>
I believe the form is not recognizing that a field has changed, but it is just a hypothesis. As I find out more things I edit.