0
What’s going on:
I have a system that, after completing the form and saving, does not save the changes by appearing a alert
"saved without changes" and back to previous page.
It does not seem to be a connection problem with the bank or the bank itself, but the form that does not recognize when some field has been changed.
Follow part of the form:
<?php
// Busca valores no banco de dados para preenchimento do formulário que quer alterar.
$id = $_GET['id'];
$sql = (" SELECT * FROM r WHERE id = '{$id}'");
$query=mysql_query($sql);
while ($campo = mysql_fetch_assoc($query)) {
?>
<div class="container">
<form method="post" action="../std/update.php" enctype="multipart/form-data" name="r" class="formulario">
<div class="container container-divisor">
<h4>Descrição R</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 class="col-md-4">
</div>
</div>
</div>
</form>
</div>
Connection to the bank:
<?php
mysql_connect("localhost","root","") or die ("erro na conexao com o banco de dados!");
mysql_select_db("db_r");
?>
Bank update:
<?php
include ("conecta.php");
$id = $_POST["idnovo"];
$dataedicao = $_POST["dataedicao"];
$datacriacao = $_POST["datacriacao"];
$statusgeral = $_POST["statusgeral"];
// Inserir dados no banco
$itens = $_POST['m'];
//$_POST['m'] as $itens
if (!empty($itens)){
$itens = implode(',', $_POST['m']);
}
$up= ("UPDATE r SET dataedicao = '$dataedicao', datacriacao = '$datacriacao', statusgeral = '$statusgeral', criadopor = '$criadopor', origem = '$origem', projet = '$projet', jalon = 'jalon', domaine = '$domaine', classification = '$classification', link = '$link', themes = '$themes', description = '$description',conseil = '$conseil', recidiv = '$recidiv', priorite = '$priorite', pilote = '$pilote', itens = '$itens', refstandard = '$refstandard', titre = '$titre', modif = '$modif', respect = '$respect', pourquoi = '$pourquoi', dataplan1 = '$dataplan1', action1 = '$action1', pilote1 = '$pilote1', metierp1 = '$metierp1', dateprevu1 = '$dateprevu1', datereal1 = '$datereal1', status1 = '$status1', link1 = '$link1', type1 = '$type1', datacomm1 = '$datacomm1', commentaire1 = '$commentaire1', suivre = '$suivre', dataplan2 = '$dataplan2', action2 = '$action2', altis2 = '$altis2', pilote2 = '$pilote2', metierp2 = '$metierp2', dateprevu2 = '$dateprevu2', datereal2 = '$datereal2', status2 = '$status2', link2 = '$link2', type2 = '$type2', datacomm2 = '$datacomm2', commentaire2 = '$commentaire2' WHERE id = '$id' ;");
$up= mysql_query($up) or die(mysql_error());
?>
<?php
if (mysql_affected_rows() > 0) {
echo '<script type="text/javascript">
alert("Salvo com Sucesso !");
window.history.go(-1);
</script>';
} else {
echo '<script type="text/javascript">
alert("Salvo sem Modificações !");
window.history.go(-1);
</script>';
}
?>
<?php
mysql_close($conexao);
?>
</body>
</html>
The Alert:
The information changed in the form is not being saved in the bank, I searched a lot for an error but so far nothing.
If you could point out the mistake or suggest something to me, I’d appreciate it.
UPDATING:
The problem has not yet been solved, but I gave a echo
in $up
and I realized that the form is not with any problem, since they are printed on the screen all the changed information. But still this information is not being saved in the bank, so the problem must be in Update.
Another thing that is being printed is the error: "Unknown column in field list"
I updated the answer. I hope it helps.
– Seu Madruga
You’re using functions like
mysql_
suggest reading this: Why we should not use mysql type functions_– Raizant
In PHP version 5.5 these functions are already discontinued, and in PHP 7 they don’t even work anymore.
– Raizant
@Knautiluz I switched everything to mysqli_, but then I re-did it with mysql_ because I think her system is completely on mysql_, so it would be a lot of work. mysql_ still works well in Php 5.6
– Seu Madruga
My php version is very old and many systems here use this version. I’m not allowed to upgrade, so I can’t use mysqli. :/
– Mariana Bayonetta