Reload content while giving Submit

2

I need to load all the content defined in the database query every while and fill in the fields and give the submit, it will write to the bank and reload only that loop bringing me the filled bank data again. So when you are posting information and recording in the database, it updates me which are filled and in the future when I load the page another day I will know which ones are filled too.

Code sample:

    while (odbc_fetch_row($result)) {

    $sqlConfirma = "SELECT inf_km, km FROM dba.km
    WHERE dba.km.id= ".$id."";

    echo "<tr>";
        echo "<form name='InsertBanco' action='executar.php' target='_blank' method='post'>
        <td><input type='text' name='km_op' value='".odbc_result($sqlConfirma, "inf_km")."'></td>
        <td><input type='text' name='km' value='".odbc_result($sqlConfirma, "km")."'></td>
        <td><input type='submit' name='InsertBanco' value='Inserir'></td>
        </form>         
        }
echo "</tr>"

This is just an example of the code, not it itself, since I use many other fields. The solution could be Javascript and Jquery as well.

    
asked by anonymous 25.08.2016 / 13:30

1 answer

2

You could enter a confirmation without being in the field using this code but with a condition, that it would only show when the submit was clicked:

if($_POST['submit']) {
    $sqlConfirma = "SELECT * FROM dba.km WHERE dba.km.id = $id";
    mysqli_query((coneccao), $sqlConfirma;

    echo 'Adicionado com sucesso á base de dados: ' . $inf_km . ', ' . $km . '.';

}

But if you prefer this way you can do it by entering this code in the value or even in the placeholder so you do not have to delete it to insert a new one.

Another way would be to end the data being saved, to generate a GET link to another page (or to the same page) with the data entered. If you choose to do this just create a header at the end of php like this:

header(Location:'(nome_do_ficheiro)?inf_km=' . '$(inf_km)' . '&amp;km=' . $(km) . '&amp;id=' . $id');

I put in parenthesis what I did not know since they are variables and files that you would have to create.

I hope I have helped, MDC

    
25.08.2016 / 15:02