Form does not import database "values"

1

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:

The fields on this edit page should be populated with the table row information (record) that was the edit button.

When you click the save button, the modified fields should be changed in the registry.

What's happening:

Although it seems all normal with the PHP function responsible for importing the information from this record to value of the field, it does not matter.

In addition, when I try to change the registry, the alert appears indicating that it was changed successfully, but when I open it in phpMyAdmin, the registry has not changed.

The connection:

<?php
    $connection = mysqli_connect("localhost", "root", "", "db_formacao");

    if (mysqli_connect_errno())
    {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
?>

The table:

<?php
//Conexão e consulta ao Mysql
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('db_formacao') or die(mysql_error());
$qry = mysql_query("select * from participantes");

//Pegando os nomes dos campos
$num_fields = mysql_num_fields($qry);//Obtém o número de campos do resultado

for($i = 0;$i<$num_fields; $i++){//Pega o nome dos campos
    $fields[] = mysql_field_name($qry,$i);
}

//Montando o cabeçalho da tabela
$table = '<table class="table table-hover table-inverse" style="margin-top:50;background-color: #37444a; color:lightgrey;"> <tr>';

for($i = 0;$i < $num_fields; $i++){
    $table .= '<th>'.$fields[$i].'</th>';
}

//Montando o corpo da tabela
$table .= '<tbody style="
    background-color: #86979e;
    color: #37444a;    
">';
while($r = mysql_fetch_array($qry)){
    $table .= '<tr>';
    for($i = 0;$i < $num_fields; $i++){
        $table .= '<td>'.$r[$fields[$i]].'</td>';
    }

    // Adicionando botão de exclusão
    $table .= '<td><form action="FormEdicao.php" method="post">'; //formulário com método post que vai para deleteF.php
    $table .= '<input type="hidden" name="ID" value="'.$r['ID'].'">';
    $table .= '<button class="btn btn-primary">Editar</button>'; //aqui está o seu botão
    $table .= '</form></td>';
}

//Finalizando a tabela
$table .= '</tbody></table>';

//Imprimindo a tabela
echo $table;

?>

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($turma, $formacao, $colaborador);
    /* NULL NULL NULL */
?>

    <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" 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="'.['ID'].'"/>
                                </div>
                            </div>
                        </fieldset>
                        <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>
                        <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 !");

        </script>';

var_dump($previsto, $realizado, $id); 
/*Ta pegando as informações certas digitadas no campo Realizado, mas não ta armazenando*/
?>

Update: When I save the update, the script says that the registry has changed successfully, but when I open the table in phpMyAdmin, the registry has not changed. In addition, the form continues no matter the bank's values;

I gave a var_dump (expected $, $ done, $ id); and NULL appears NULL NULL

    
asked by anonymous 01.09.2017 / 18:40

1 answer

2

The answer was simpler than I thought.

On the Table page we have:

$table .= '<input type="hidden" name="ID" value="'.$r['ID'].'">';

This ensures that the ID is being passed when the edit button is clicked.

Doing the same for the other fields too:

    $table .= '<input type="hidden" name="ID" value="'.$r['ID'].'">';
    $table .= '<input type="hidden" name="FORMACAO" value="'.$r['FORMACAO'].'">';
    $table .= '<input type="hidden" name="TURMA" value="'.$r['TURMA'].'">';
    $table .= '<input type="hidden" name="COLABORADOR" value="'.$r['COLABORADOR'].'">';

Problem solved! :)

    
06.09.2017 / 15:02