Form does not receive registered data

0

What's happening:

I have a system that, when you finish filling out the form and saving, does not save the changes appearing a alert "saved without changes" and returning to the 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 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>

O alert: Theinformationchangedintheformarenotbeingsavedinthedatabase,Isearchedalotforanerrorbutsofarnothing.Ifyoucanpointmetotheerrororsuggestsomething,Iwouldappreciateit.

UPDATE:

Theproblemhasnotyetbeensolved,butIhavegivenechoto$upandInoticedthattheformdoesnothaveaproblem,sinceallchangedinformationisprintedonthescreen.Butstillthisinformationisnotbeingsavedinthedatabase,sotheproblemshouldbeinUpdate.Anotherthingthatisbeingprintedistheerror:"Unknown column in field list"

    
asked by anonymous 31.07.2017 / 14:27

1 answer

2

Hello. I noticed two things there in your code.

The first is the line: //$up = mysql_query("UPDATE retex SET dataedicao (...)

Is this line really commented? Try to remove the "//" because this indicates a comment, so the interpreter ignores the statement, and that's just the instruction to write changes to the database (is not it?).

Second thing I noticed is this section:

<?php
    if(mysql_affected_rows() > 0){
    ?>  
<script type="text/javascript">
    alert("Salvo com Sucesso !");
    window.history.go(-1);
</script>
<?php
        }
        else{
?>
</script>
<script type="text/javascript">
    alert("Salvo sem Modificações !");
    window.history.go(-1);
</script>

Note that the script tags are outside Php blocks, so they will be echoed anyway. Therefore, both the first and second blocks of scripts will be present in the final file that will be sent to the browser. So try changing to:

<?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>';
    }
?>

Another detail: close the input tags with /> instead of just > . I know most modern browsers ignore it, but it's interesting to test to see.

UPDATE: I noticed two more things.

First: variable $statusgeral is not populated, right? It looks like $_POST['statusgeral'] does not exist, since it does not have this field in the form.

Second thing: closing input text is 127> , change to only > . This may be bugging the form.

UPDATE 2

I replicated the application here and it worked perfectly with minor changes I made. The code is commented but, having any doubts, just talk.

connect.php: with no changes here

<?php
mysql_connect("localhost","root","") or die ("erro na conexao com o banco de dados!");
mysql_select_db("db_r");

Form Page:

<?php
    // Busca valores no banco de dados para preenchimento do formulário que quer alterar.
    // Mudei include para require
    require 'conecta.php';
    $id = $_GET['id'];
    $query = "SELECT * FROM r WHERE id = '{$id}'";
    $query = mysql_query($query) or die (mysql_error());   
 ?>

<div class="container">
<!-- Iniciei o "while loop" aqui embaixo.
OBS: corrija o URL da action="" para o seu URL. Eu mudei pois fiz tudo em uma só pasta -->
<?php while ($campo = mysql_fetch_assoc($query)) : ?>
<form method="post" action="./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'];?>">
             <!--  Alterei o value do dataedicao para o formate Ano/Mes/Dia Hora:minutos:segundos (timestamp). -->
            <input type="hidden" name="dataedicao" id="dataedicao" value="<?= date("Y/m/d H:i:s") ?>">
            <div class="col-md-4">
                <label for="datacriacao">Data</label>
                <input type="text" class="form-control" name="datacriacao" id="dataCriacao" value="<?=$campo['datacriacao'];?>"127>
                <!-- inseri um botão para enviar o formulário, uma vez que não sei como você está fazendo para enviá-lo -->
                    <input type="submit" value="enviar" id="send" />
            </div>
            <div class="col-md-4">
            </div>
        </div>
    </div>
</form>
<?php endwhile; ?>
</div>

Update.php

<?php 
// Mudei o include para require
require 'conecta.php';

// tudo igual por aqui, apenas atribui um valor qualquer à variável $statusgeral
$id             =   $_POST["idnovo"]; 
$dataedicao     =   $_POST["dataedicao"];
$datacriacao    =   $_POST["datacriacao"];
$statusgeral    =   'ativo';

// Montei o texto da query fora do mysql_query e alterei tudo para o formato '{$campo}', ao invés de só '$campo'    
$qr = "UPDATE retex SET dataedicao = '{$dataedicao}', datacriacao = '{$datacriacao}', statusgeral = '{$statusgeral}' WHERE id = '{$id}' ";
$qr = mysql_query($qr) or die(mysql_error());

// Verifica se foram atualizados os dados e printa na tela 
if (mysql_affected_rows() > 0):
    echo "Atualizado";
else:
    echo "Nada foi atualizado";
endif;

NOTE: Because the id is being passed via GET, it is important to remember that you need to enter it in the URL. It occurred to me that maybe you're forgetting that. It looks like this: link

Update 3

$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'";
    
31.07.2017 / 15:36